[R] ggplot2 question plot mean/error bars

Santosh santosh2005 at gmail.com
Wed Apr 5 20:50:02 CEST 2017


Hello Rxperts..
I am trying to generate a mean+/- error plot.. using ggplot2.. with filled
black and white circles and black lines, but no overlap  of lines and
circles (symbols). Also, with no top and right lines of the plot box. I
remember having done this before.. unable to reproduce how I did!

Yes, there are many ways of generating the plot.. Would high appreciate it
if you could help debug this piece of code.

Attaching sample code for your convenience..
Best,
Santosh

q <-
 data.frame(G=rep(paste("G",1:3,sep=""),each=50),D=rep(paste("D",1:5,sep=""),each=30),a=rep(1:15,each=10),t=rep(seq(10),15),b=round(runif(150,10,20)))
q$r <- q$b*0.1
q2 <- q[order(q$G,q$D,q$a,q$t),]

  q3 <-
as.data.frame(as.matrix(with(q2,aggregate(list(b=b),list(D=D,t=t),function(x)
c(mean=mean(x),sd=sd(x),se=(sd(x)/sqrt(length(x))))))),stringsAsFactors=F)
  q3$t <- as.numeric(q3$t)
  q3$b.mean <- as.numeric(q3$b.mean)
  q3$b.sd <- as.numeric(q3$b.sd)
  q3$b.se <- as.numeric(q3$b.se)

ggplot(q3[as.character(q3$D)%in%c("D1","D2"),],aes(x=t,y=b.mean,fill=D,col=D,group=D))
+     geom_point(shape=21,size=4) +
    geom_line() +
geom_errorbar(width=1,aes(ymin=Mean-SE,ymax=Mean+SE)) +
geom_errorbar(width=1,aes(ymin=Mean-SE,ymax=Mean+SE)) +
    scale_shape_manual(values = c(16,21)) +
    scale_fill_manual(values=c("black","white")) +
    scale_color_manual(values=c("black","black")) +
    +legend.position = c(.8,.8))

	[[alternative HTML version deleted]]



More information about the R-help mailing list