Hi, I'm trying to do a box-whisker plot of two columns of a data frame, a list of category names in one column vs. some numerical values in the other. The plot itself works fine, but only a few points of the x-axis ( the category names ) are labelled. I think that this is because the category names are too long. Is there any way to force R to label each x-axis value, preferably at a 45-degree slant so that each one can be seen? I feel like this should be pretty easy to do, but I can't find anything obvious from the R-manual. Thanks for any help, Bill
Bill Kranec wrote:> Hi, > > I'm trying to do a box-whisker plot of two columns of a data frame, a > list of category names in one column vs. some numerical values in the > other. The plot itself works fine, but only a few points of the x-axis > ( the category names ) are labelled. I think that this is because the > category names are too long. > > Is there any way to force R to label each x-axis value, preferably at a > 45-degree slant so that each one can be seen? I feel like this should be > pretty easy to do, but I can't find anything obvious from the R-manual. > > Thanks for any help, > > Bill >You might find the "staxlab" function in the "plotrix" package helpful. Jim
Bill Kranec a ?crit :> Hi, > > I'm trying to do a box-whisker plot of two columns of a data frame, a > list of category names in one column vs. some numerical values in the > other. The plot itself works fine, but only a few points of the x-axis > ( the category names ) are labelled. I think that this is because the > category names are too long. > > Is there any way to force R to label each x-axis value, preferably at a > 45-degree slant so that each one can be seen? I feel like this should be > pretty easy to do, but I can't find anything obvious from the R-manual. > > Thanks for any help, > > Bill > > ______________________________________________ > 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 >For example: test <- data.frame( y = rnorm(120), x = rep(month.name, each = 100)) library(lattice) bwplot(y ~ x, data = test, scales = list(x = list(rot = 45))) Best, Renaud -- Dr Renaud Lancelot, v?t?rinaire C/0 Ambassade de France - SCAC BP 834 Antananarivo 101 - Madagascar e-mail: renaud.lancelot at cirad.fr tel.: +261 32 40 165 53 (cell) +261 20 22 665 36 ext. 225 (work) +261 20 22 494 37 (home)
On Sun, 2005-03-20 at 23:15 -0500, Bill Kranec wrote:> Hi, > > I'm trying to do a box-whisker plot of two columns of a data frame, a > list of category names in one column vs. some numerical values in the > other. The plot itself works fine, but only a few points of the x-axis > ( the category names ) are labelled. I think that this is because the > category names are too long. > > Is there any way to force R to label each x-axis value, preferably at a > 45-degree slant so that each one can be seen? I feel like this should be > pretty easy to do, but I can't find anything obvious from the R-manual.Bill, there have been a couple of other suggestions, but I'll throw in my $0.02 here: Without a specific example it is hard to know which way to recommend to you, but a couple of possibilities if you are using R's base graphics: 1. Reduce the font size of the labels by using 'cex.axis' as an argument in your call to boxplot(). The default is 1, but you may be able to reduce it to something that gets your labels printed and still be readable. Here is an example: group <- sample(c("Long Label 1", "Long Label 2", "Long Label 3"), 40, replace = TRUE) N <- rnorm(40) df <- data.frame(group, N) boxplot(N ~ Group, data = df) # Now reduce the size of the labels boxplot(N ~ group, data = df, cex.axis = 0.75) 2. You can split the labels on two lines by using a "\n" in the labels: boxplot(N ~ group, data = df, xaxt = "n") mtext(1, at = 1:3, text = c("Long\nLabel 1", "Long\nLabel 2", "Long\nLabel 3"), line = 2) If you want to reduce the font size in the above use 'cex = ...' in the call to mtext(). 3. If neither of the above (or a combination of the two) helps, there is a FAQ (7.27) that provides an example of how to rotate axis labels at: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated- axis-labels_003f Beware of line wrapping in the above URL. HTH, Marc Schwartz