[R] Lines connecting the boxes in a boxplot

Arne Brutschy abr-r-project at xylon.de
Sat Jun 16 10:38:19 CEST 2007


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"))



More information about the R-help mailing list