ggplot2 offset scatterplot points

前端 未结 4 1895
别跟我提以往
别跟我提以往 2020-12-05 19:54

I have two sets of points with error bars. I would like to offset the second so it\'s displayed slightly down from the first set, so that it doesn\'t obscure the original.<

4条回答
  •  执念已碎
    2020-12-05 20:10

    Using Richie's reorganization of your data, this is also possible purely within ggplot, without having to mess with the axis:

    dodge <- position_dodge(width=0.5)  
    p <- ggplot(dfr,aes(x=y,y=x,colour=type)) + 
            geom_point(aes(shape=type),position=dodge) +
            geom_errorbar(aes(ymax=upper,ymin=lower),position = dodge) + 
            scale_colour_manual(values = c('gray','black')) +
            scale_shape_manual(values = c(8,19)) +
            coord_flip() + 
            opts(legend.position="none")
    

    which gives me this plot:

    enter image description here

    Note: Since version 0.9.2 opts has been replaced by theme:

    + theme(legend.position = "none")
    

提交回复
热议问题