2013-04-30 37 views
1

,我有以下數據,以產生GGPLOT2條形圖(R)定製條形圖中的R

Bin Plr groupname data ci 
3 1% solution 1002.97 6.98322 
10 1% solution 1001.7 1.25921 
30 1% solution 1176.47 12.1888 
3 1% w/o solution 1206.76 6.97126 
10 1% w/o solution 1211.65 1.81174 
30 1% w/o solution 1395.84 15.8956 
3 4% solution 1003.25 6.98989 
10 4% solution 1002.14 0.870957 
30 4% solution 1217.76 45.8752 
3 4% w/o solution 1207.18 6.99091 
10 4% w/o solution 1210.35 1.97528 
30 4% w/o solution 1470.81 48.6673 

於是,我找了分組的兩個層次。任何人都可以建議我如何有以下柱形圖由ggplot在R. http://oi42.tinypic.com/2s8rb7m.jpg

+0

我已經試過分組的一個級別的圖表(僅使用組名),這很容易。像qplot(factor(Bin),data = my_data,geom =「bar」,fill = groupname,weight = data,position =「dodge」,main =「使用解決方案獲得的收益」,xlab =「Size」,ylab =「Time [ms]」)+ geom_errorbar(aes(ymin = data-ci,ymax = data + ci),width = .2,position = position_dodge(.9)) – Timir 2013-04-30 15:56:15

+0

如果您在url中看到圖片,將找到使用Plr進一步分組,但具有相同的分組組合 – Timir 2013-04-30 15:59:15

+0

我通常對簡單的x和y圖使用qplot,對於更復雜的分組使用ggplot語法。我不知道它是否是最佳做法,但... – 2013-04-30 16:00:03

回答

0

試試這個:

ggplot(my_data, aes(x=bin, y=data, fill=groupname)) 
+ geom_bar(stat="identity", position="dodge") 
+facet_wrap(~ plr) 
+labs(title = "Gains from using the solution", x= "size", y= "time[ms]") 

EDIT2:SRY,投x作爲因子,因此其不會對線性需要去規模。也使用寬度將其縮小一點以匹配ur樣本圖。我的新想法:

(ggplot(my_data, aes(x=factor(Bin), y=data, fill=groupname, width=.65)) 
+ geom_bar(stat="identity", position="dodge") 
+facet_wrap(~Plr) 
+labs(title = "Gains from using the solution", x= "size", y= "time[ms]") 
+ geom_errorbar(aes(ymin=data-ci, ymax=data+ci),position="dodge") 
) 
+0

這只是使10到30之間的空間,你是什麼意思? – Timir 2013-04-30 16:02:06

+0

您是否使用該代碼的確切表? – 2013-04-30 16:03:10

+0

是的。我試過你的建議,它非常接近。 – Timir 2013-04-30 16:08:35

0

使用從綠色惡魔的幫助下,我找到了正確的方法,使我需要

ggplot(my_data, aes(x=factor(Bin), y=data, fill=groupname, width=.65)) + 
     geom_bar(stat="identity", position="dodge")+facet_wrap(~Plr) + 
     labs(title = "Gains from using the solution", x= "size", y= "time[ms]", 
            linetype='custom title',fill="") + 
     geom_errorbar(aes(ymin=data-ci, ymax=data+ci), 
            width=0.25,position=position_dodge(0.65)) 

enter image description here