Add a segment only to one facet using ggplot2

后端 未结 1 406
陌清茗
陌清茗 2021-01-03 03:07

As an example, I have this data frame, called my_data:

         Groups    FactorA    FactorB    FactorC N    value         sd        se                  


        
相关标签:
1条回答
  • 2021-01-03 03:31

    Put the data for the segment in data frame and also add columns FactorB and FactorC with levels for which you need to draw the segment.

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

    Now use this data frame to add segment. Also add inherit.aes=FALSE inside geom_segment() to ignore fill=FactorA set in ggplot().

      + geom_segment(data=data.segm,
                   aes(x=x,y=y,yend=yend,xend=xend),inherit.aes=FALSE)+
    

    enter image description here

    0 讨论(0)
提交回复
热议问题