I am trying to draw a graph using ggplot, geom_poitrange. I have two groups, each one with two points and corresponding error values. the code I use is below:
group<-c("A","A","B","B")
val<-c(1.3,1.4, 1.2,1.5)
SD<-c(0.3,0.8,0.6,0.5)
RX<-c("X","Z","X","Z")
a<-data.frame(group,val,SD,RX)
ggplot(data=a)+
geom_pointrange(aes(x=RX, y=val, ymin=(val-SD), ymax=(val + SD),
group=group, color=group, position_dodge(width=4)), size=1.5)
With this I obtain a nice graph, but the groups overlap. enter image description here
I wanted to offset them. I tried the following:
geom_pointrange(aes(x=RX, y=val, ymin=(val-SD), ymax=(val + SD),
group=group, color=group, position_dodge(width=1)), size=1.5)
or
geom_pointrange(aes(x=RX, y=val, ymin=(val-SD), ymax=(val + SD),
group=group, color=group, position="dodge"), size=1.5)
and variations of the above. Can anyone suggest what I am doing wrong? Thanks
position
argument should not be insideaes
, which is described in?geom_pointrange
and?position_dodge
; (2) yourwidth
is too large; (3) you don't needgroup
because you already 'group' your data usingcolor = group
. – Henrik