[R] Changing x-axis on boxplot

Tim Clark mudiver1200 at yahoo.com
Sun Sep 26 08:13:45 CEST 2010


Dear List,
 
I am creating a boxplot with two subsets, very similar to the example by Roger 
Bivand at ?boxplot (reproduced below).  I am trying to change the labels on the 
x-axis to have one number to cover both subsets.  I can do this in other plots 
by using axis=FALSE followed by a separate axis() command.  I have also tried 
variations in the names= argument but can't get it to work.  Ideally I would 
like tickmarks on either side of each factor with the number for the level 
centered between the two tick marks.  Any suggestions?
 
Thanks,
 Tim 

Example:

boxplot(len ~ dose, data = ToothGrowth,
        boxwex = 0.25, at = 1:3 - 0.2,
        subset = supp == "VC", col = "yellow",
        main = "Guinea Pigs' Tooth Growth",
        xlab = "Vitamin C dose mg",
        ylab = "tooth length",
        xlim = c(0.5, 3.5), ylim = c(0, 35), yaxs = "i")
boxplot(len ~ dose, data = ToothGrowth, add = TRUE,
        boxwex = 0.25, at = 1:3 + 0.2,
        subset = supp == "OJ", col = "orange")
legend(2, 9, c("Ascorbic acid", "Orange juice"),
       fill = c("yellow", "orange"))


 Tim Clark

Marine Ecologist
National Park of American Samoa


     


More information about the R-help mailing list