0

I want to adjust this plot to avoid the overlapping of the vertical lines and connect all the points with the same color (see graph below).

code:

library(ggplot2)
dat=read.csv("data.csv",header=T)

p<-ggplot(dat, aes(x=population, y=resp, group=population,color=cov)) + 
  geom_pointrange(aes(ymin=resp-sd, ymax=resp+sd))

enter image description here

Data

    resp    cov population  sd  

    42.07   X1      A      0.33 
    
    41.92   X1      B      0.54 
    
    42.2    X1      C      0.25 
    
    41.92   X1      D      1.15 
    
    41.98   X1      E      1.35
    
    42.5    X1      F      0.51
    
    42.85   X1      G      0.35
    
    38.37   X2      A      0.13

    .....  
Community
  • 1
  • 1
Aldo
  • 1
  • 2

1 Answers1

0

You can try to change the position argument to avoid the overlapping lines:

p<-ggplot(dat, aes(x=population, y=resp, group=population,color=cov)) + 
  geom_pointrange(aes(ymin=resp-sd, ymax=resp+sd), position = position_dodge(width = 0.2)
Jeffrey Girard
  • 761
  • 4
  • 20