[R] Lines connecting the boxes in a boxplot

Christoph Buser buser at stat.math.ethz.ch
Mon Jun 18 09:23:26 CEST 2007


Dear Arne

I' recommend to save the information of your boxplots

a <- boxplot(...)
str(a)

Then you have the information that you need about your boxplot
(e.g. the value of the median) and can use segments() to draw
the lines you want.

Hope this helps

Best regards,

Christoph

--------------------------------------------------------------

Credit and Surety PML study: visit our web page www.cs-pml.org

--------------------------------------------------------------
Christoph Buser <buser at stat.math.ethz.ch>
Seminar fuer Statistik, LEO C13
ETH Zurich	8092 Zurich	 SWITZERLAND
phone: x-41-44-632-4673		fax: 632-1228
http://stat.ethz.ch/~buser/
--------------------------------------------------------------


Arne Brutschy writes:
 > Hello,
 > 
 > I'm currently using a boxplot to visualize data for three different
 > models. As I have three models, I'm plotting three parallel boxplots
 > for each factor.
 > 
 > This works fine - what I need now is a line connecting the medians of
 > each boxplot of each model. I want to do this in order to visualize
 > the trend that one of the models exhibit. Basically, I want to plot a
 > curve for each model (slightly offset on the x axis), with a boxplot
 > on each datapoint.
 > 
 > It's only an idea, and I don't know if it's not too confusing after
 > adding the lines... Is it possible? Has anyone done this before?
 > 
 > Sorry if this has been asked before or is a standard feature, I simply
 > have now clue how to name the feature I want. Ergo: I cannot search
 > for it.. :\
 > 
 > Regards,
 > Arne
 > 
 > PS: this is my current code
 > 
 > require(gplots)
 > boxwex=0.15
 > 
 > data <- read.table("all_runs_fitness.data");
 > colnames(data)=c("model","matrix","fitness")
 > 
 > boxplot(fitness ~ matrix,
 >         data=data, boxwex=boxwex, at=(1:7 - 0.2),
 >         main="Fitness for Matrix/Models", xlab="Matrixtype",
 >         ylab="Fitness", ylim=c(20,100), 
 >         subset=(model=="dyn"), col="lightblue", xaxt="n", whisklty=1)
 > boxplot(fitness ~ matrix,
 >         data=data, boxwex=boxwex, at = 1:7, add=TRUE, 
 >         subset=(model=="dl3"), col="mistyrose", xaxt="n", whisklty=1)
 > boxplot(fitness ~ matrix,
 >         data=data, boxwex=boxwex, at=(1:7 + 0.2), add=TRUE, 
 >         subset=(model=="dl4"), col="lightcyan", xaxt="n", whisklty=1)
 > 
 > axis(1, 1:8-0.5, labels=FALSE)
 > axis(1, 1:7, tck=FALSE, labels=levels(data[,2]))
 > 
 > smartlegend(x="left", y="bottom", inset = 0.01,
 >             c("dyn","dl3","dl4"), fill = c("lightblue", "mistyrose", "lightcyan"))
 > 
 > ______________________________________________
 > R-help at stat.math.ethz.ch 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.



More information about the R-help mailing list