2016-09-18 46 views
0

在我的圖中,我有重疊,試圖使用position_dodge的位置,但無濟於事。我做了一個示例程序重現該問題:閃避不起作用

data1 <- data.frame(source=c("group1", "group1"), q=c("Q1", "Q2"), mean=c(2.6, 1.9), se=c(0.16, 0.4)) 
data2 <- data.frame(source=c("group2", "group2"), q=c("Q1", "Q2"), mean=c(2.4, 0.9), se=c(0.2, 0.1)) 
pd <- position_dodge(1) 
ggplot(data1) + 
    geom_errorbar(data=data1, position=pd, width=.3, aes(x=q,ymin=mean-se,ymax=mean+se,color=source)) + 
    geom_point(size=3, position=pd,data = data1, aes(x=q, y=mean, color=source, shape=source)) + 
    geom_errorbar(data=data2, position=pd, width=.3, aes(x=q,ymin=mean-se,ymax=mean+se,color=source)) + 
    geom_point(size=3, position=pd,data = data2, aes(x=q, y=mean, color=source, shape=source)) 

enter image description here

我在做什麼錯?

回答

2

Dodgind無法工作,因爲您有兩個數據框。把所有的數據放在一個數據框中,然後它就會工作。

data3<-rbind(data1,data2) 
ggplot(data3)+ 
     geom_errorbar(position=pd, width=.3, aes(x=q,ymin=mean-se,ymax=mean+se,color=source)) + 
     geom_point(size=3, position=pd,aes(x=q, y=mean, color=source, shape=source))