R 使用ggplot2仅向一个面添加线段

R 使用ggplot2仅向一个面添加线段,r,graph,ggplot2,segment,facets,R,Graph,Ggplot2,Segment,Facets,例如,我有一个数据框,称为my_data: Groups FactorA FactorB FactorC N value sd se ci 1 Control Condition1 Condition1 Condition1 3 92.00000 6.0827625 3.511885 15.110420 2 Control Condition1 Condition1 Condit

例如,我有一个数据框,称为
my_data

         Groups    FactorA    FactorB    FactorC N    value         sd        se         ci
1       Control Condition1 Condition1 Condition1 3 92.00000  6.0827625  3.511885  15.110420
2       Control Condition1 Condition1 Condition2 2 69.00000  8.4852814  6.000000  76.237228
3       Control Condition1 Condition2 Condition1 3 72.33333 10.2632029  5.925463  25.495209
4       Control Condition1 Condition2 Condition2 2 97.00000  2.8284271  2.000000  25.412409
5       Control Condition2 Condition1 Condition1 3 85.00000 13.0000000  7.505553  32.293790
6       Control Condition2 Condition1 Condition2 2 78.50000 16.2634560 11.500000 146.121354
7       Control Condition2 Condition2 Condition1 3 95.00000  5.1961524  3.000000  12.907958
8       Control Condition2 Condition2 Condition2 2 78.00000 22.6274170 16.000000 203.299276
9  Experimental Condition1 Condition1 Condition1 2 80.00000  5.6568542  4.000000  50.824819
10 Experimental Condition1 Condition1 Condition2 3 74.00000 19.9248588 11.503623  49.496093
11 Experimental Condition1 Condition2 Condition1 2 68.50000  0.7071068  0.500000   6.353102
12 Experimental Condition1 Condition2 Condition2 3 78.66667 18.5831465 10.728985  46.163095
13 Experimental Condition2 Condition1 Condition1 2 81.00000 19.7989899 14.000000 177.886866
14 Experimental Condition2 Condition1 Condition2 3 75.33333 17.0391706  9.837570  42.327646
15 Experimental Condition2 Condition2 Condition1 2 81.50000 14.8492424 10.500000 133.415150
16 Experimental Condition2 Condition2 Condition2 3 78.00000  5.2915026  3.055050  13.144821
使用此代码创建

my_data <- data.frame(Groups=c(rep("Control",20),rep("Experimental",20)),
                      FactorA=rep(c("Condition1","Condition2"),20),
                      FactorB=rep(c("Condition1","Condition1","Condition2","Condition2"),10),
                      FactorC=rep(c(rep("Condition1",4),rep("Condition2",4)),5),
                      value=sample(60:100,40,replace=T)
                      )

# add standard errors with a specific function    
my_data <- summarySE(my_data,
                     measurevar="value",
                     groupvars=c("Groups","FactorA","FactorB", "FactorC"))
我得到这个阴谋

如您所见,使用线
geom_段(x=0.8,y=100,xend=1.2,yend=100)
会出现四个段,每个面一个,但我只想在一个面中绘制一个段(例如,在左上方的绘图中)


有人能帮帮我吗?我尝试了各种解决方案,但没有任何结果。

将段的数据放在数据框中,并添加列
FactorB
FactorC
,其中包含需要绘制段的级别

data.segm<-data.frame(x=0.8,y=100,xend=1.2,yend=100,
                      FactorB="Condition1",FactorC="Condition1")

Didzis,我更新了我的问题,因为为了简单起见,我没有插入错误条,但我需要它们。我以为这不重要,对不起。我无法移动
fill=FactorA
,因为这会更改错误条的正确位置。请你更新一下你的答案好吗?非常感谢你的帮助。我用这个解决了一个微笑的问题,谢谢。有没有办法改变线段的颜色和线型?在创建数据帧时,我尝试添加
linetype=“虚线”,color=“red”
,但段仍然是实心和黑色。编辑:将其直接添加到
geom_段
调用工作正常。
data.segm<-data.frame(x=0.8,y=100,xend=1.2,yend=100,
                      FactorB="Condition1",FactorC="Condition1")
  + geom_segment(data=data.segm,
               aes(x=x,y=y,yend=yend,xend=xend),inherit.aes=FALSE)+