[R] Center labels on a boxplot

About this list Date view Thread view Subject view Author view Attachment view

From: Andy Bunn (abunn@montana.edu)
Date: Thu 11 Mar 2004 - 03:34:54 EST


Message-id: <002301c406bd$a143feb0$78f05a99@msu.montana.edu>

Suppose that I have data on three species for a variable and datasets
from two time periods. I want to make a boxplot of the first dataset and
then add the second using 'at = ' and 'add = T' as in the example for
'boxplot.'

Since the boxes are paired by species, I want to do is have the x labels
be centered between the boxes. I'm doing this now with mtext and
entering spaces to make them center. There must be a better way.

Much thanks, Andy

   #######################
   myDF1 <- data.frame(spp1 = c(0,0,0,0,1,0,1,1,0,0,0,1),
                        spp2 = c(1,0,1,1,0,0,0,0,1,0,0,0),
                        spp3 = c(0,1,0,0,0,1,0,0,0,1,1,0),
                        aVar = runif(12, 1, 10) + 1:12)

    myDF2 <- data.frame(spp1 = c(1,1,0,0,0,0,0,0,1,0,0,1),
                        spp2 = c(0,0,1,1,0,0,0,1,0,0,1,0),
                        spp3 = c(0,0,0,0,1,1,1,0,0,1,0,0),
                        aVar = runif(12, 1, 10) + 1:12)

    boxplot(aVar ~ spp1 + spp2 + spp3, data = myDF1, boxwex = 0.25, at =
1:3 - 0.2,
                       names = c("","",""),
                       ylab = "A Varirable of Extreme Interest",
                       ylim = c(0,24))

    boxplot(aVar ~ spp1 + spp2 + spp3, data = myDF2, boxwex = 0.25, at =
1:3 + 0.2,
                       names = c("","",""), add = T, col="gray")
 
    legend(0.5, 24, c("Time 1", "Time 2"),
           fill = c("white", "gray"))
 
    
   mtext("SPP1, SPP2, SPP3",.....)
   #########################

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Fri 23 Apr 2004 - 18:36:35 EST