2012-02-21 100 views
2

使用sciplot庫中的lineplot.CI製作交互圖時,錯誤條可以跨組重疊。例如,r/sciplot:lineplot.CI中的重疊晶須

data = c(1,5,3,7,3,7,5,9) 
grp1 = c(1,1,1,1,2,2,2,2) 
grp2 = c(1,1,2,2,1,1,2,2) 
lineplot.CI(grp1, data, grp2) 

該基團可以是沿x軸通過添加抖動分組變量和設定x.cont爲TRUE分離,但是這使得在圖中的線消失:

data = c(1,5,3,7,3,7,5,9) 
grp1 = c(1,1,1,1,2,2,2,2) + c(-0.05, -0.05, 0.05, 0.05, -0.05, -0.05, 0.05, 0.05) 
grp2 = c(1,1,2,2,1,1,2,2) 
lineplot.CI(grp1, data, grp2, x.cont=TRUE) 

是否有可能出現線條並抖動點,以便誤差線不重疊?或者有更好的方法來製作這種情節?

回答

4

您可以使用ggplot2。這裏是一個內置數據集的例子(因爲我沒有你的標準錯誤或配置項)。關鍵是要使用position_dodge()

ToothGrowth$dose.cat <- factor(ToothGrowth$dose, labels=paste("d", 1:3, sep="")) 
df <- with(ToothGrowth , aggregate(len, list(supp=supp, dose=dose.cat), mean)) 
df$se <- with(ToothGrowth , aggregate(len, list(supp=supp, dose=dose.cat), 
       function(x) sd(x)/sqrt(10)))[,3] 

opar <- theme_update(panel.grid.major = theme_blank(), 
        panel.grid.minor = theme_blank(), 
        panel.background = theme_rect(colour = "black")) 

xgap <- position_dodge(0.2) 
gp <- ggplot(df, aes(x=dose, y=x, colour=supp, group=supp)) 
gp + geom_line(aes(linetype=supp), size=.6, position=xgap) + 
    geom_point(aes(shape=supp), size=3, position=xgap) + 
    geom_errorbar(aes(ymax=x+se, ymin=x-se), width=.1, position=xgap) 
theme_set(opar) 

enter image description here