On Aug 22, 2011, at 12:14 PM, Sébastien Vigneau wrote: > Hi, > > I would like to draw a stacked bar chart with four bars (say "a", "b", "c", > "d") . Two bars belong to group A and the two others to group B. Therefore, > I would like to have, on the x-axis, a label for each bar and an additional > label for each group, positioned underneath. To give an idea, the x-axis > labels should look like this: > |a|b|c|d| > | A | B | > > Do you know how I can generate such two-levels labels in R? > > Thank you for your help! > > Sebastien
See ?barplot and note in the Value section: If beside is true, use colMeans(mp) for the midpoints of each group of bars, see example. Here is another example: mat <- matrix(1:4, ncol = 2) mp <- barplot(mat, beside = TRUE) Groups <- c("A", "B") Sub.Groups <- c("a", "b", "c", "d") mtext(side = 1, line = 1, at = mp, text = Sub.Groups) mtext(side = 1, line = 3, at = colMeans(mp), text = Groups) HTH, Marc Schwartz ______________________________________________ R-help@r-project.org 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.