Quantcast

Help boxplot to add mean, standard error and/or stadard deviation

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Help boxplot to add mean, standard error and/or stadard deviation

gianni lavaredo
Dear researchers

I wish to plot a box plot without the mean line (the black line) and plot
only the mean (red square). Futhermore, is it possible to add standard
error and/or stadard deviation?

This is an example

mytest <- c(2.1,2.6,2.7,3.2,4.1,4.3,5.2,5.1,4.8,1.8,1.4,2.5,2.7,3.1,2.6,2.8)
boxplot(mytest,lty = "solid")
means <- mean(mytest,na.rm=TRUE)
points(means, pch = 22, col = "red")

thanks in advance

Gianni

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Help boxplot to add mean, standard error and/or stadard deviation

Jim Lemon
On 01/30/2012 11:56 PM, gianni lavaredo wrote:
> Hey Thanks Jim,
>
> is It possible to plot in the same plot mean, standard error AND
> standard deviation. As in figure 3 of the paper I attached
>
Hi gianni,
Here is a rather rough function that will do more or less what you want.
You can choose any two measures of dispersion and plug them in as
ulim/llim (outer) and uinner/linner (inner). The example shows how you
can get asymmetric dispersion measures. For symmetric measures, you only
have to pass ulim and uinner. You will probably have to do a little
refining on the function to get exactly what you want.

box.heresy<-function(x,y,uinner,linner=uinner,ulim,llim=ulim,
  intervals=FALSE,arrow.cap=0.01,pch=22,main="",xlab="",ylab="",
  xaxlab=NA,col="white",...) {

  if(missing(y)) {
   y<-x
   x<-1:length(y)
  }
  if(is.na(xaxlab)) xaxlab<-x
  if(intervals) {
   ulim<-y+ulim
   llim<-y-llim
  }
  xrange<-range(x)
  xspace<-diff(xrange)/10
  boxwidth<-diff(xrange)/(4*length(x))
  plot(x,y,xlim=c(xrange[1]-xspace,xrange[2]+xspace),
   ylim=range(c(llim,ulim)),
   main=main,xlab=xlab,ylab=ylab,type="n",xaxt="n")
  axis(1,at=x,labels=xaxlab)
  dispersion(x,y,ulim,llim,intervals=FALSE,arrow.cap=arrow.cap,...)
  if(intervals) {
   uinner<-y+uinner
   linner<-y-linner
  }
  rect(x-boxwidth,linner,x+boxwidth,uinner,col=col)
  points(x,y,pch=pch)
}

require(plotrix)
y<-runif(5)
ulim<-runif(5)
llim<-runif(5)
uinner<-ulim/2
linner<-llim/2
box.heresy(y,uinner=uinner,linner=linner,ulim=ulim,llim=llim,
  intervals=TRUE,main="The heretical boxplot",
  xlab="Number of observations",ylab="Value")

Have fun.

Jim

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Loading...