[R] method or package to make special boxplot

Jim Lemon jim at bitwrit.com.au
Sun Sep 9 16:39:55 CEST 2012


On 09/09/2012 12:14 AM, Zhang Qintao wrote:
> Hi, All,
>
> I am trying to use R to make the following type of boxplot while I couldn't
> find a way to do it.
>
> My dataset looks like X1 Y1 X2 Y2.... SPLIT. The split highlights my
> experiment details and both x and y are continuous numerical values.  I
> need to plot y vs. x with split as legend and boxplot has to be used for
> all splits. May I ask how to get it? Currently available boxplot only
> applies on the case that X axis is character.
>
Hi Qintao,
Do you want a sort of 2D boxplot? The example below gives a rough idea 
as to what it would look like, with boxplots for your Xs and Ys centered 
at their medians and an abcissa with the labels for your splits. Needs a 
bit of work to turn this into a function, so let me know if it does what 
you want.

Jim

x1<-rnorm(10)
y1<-rnorm(10)
y2<-rnorm(10)
x2<-rnorm(10)
x1sum<-boxplot(x1)
y1sum<-boxplot(y1)
offset=4
x2sum<-boxplot(x2,at=median(y2)+offset,add=TRUE)
y2sum<-boxplot(y2+offset)
bxp(x1sum,at=median(y1),xlim=c(y1sum$stats[1],y2sum$stats[5]),
  ylim=c(min(c(x1sum$stats[1],x2sum$stats[1])),
  max(c(x1sum$stats[5],x2sum$stats[5]))),axes=FALSE)
bxp(y1sum,at=median(x1),add=TRUE,horizontal=TRUE,axes=FALSE)
bxp(x2sum,at=median(y2+offset),add=TRUE,axes=FALSE)
bxp(y2sum,at=median(x2),horizontal=TRUE,add=TRUE,axes=FALSE)
box()
axis(2)
axis(1,at=c(median(y1),median(y2)+offset),labels=c("Split1","Split2"))




More information about the R-help mailing list