[R] Two-levels labels on x-axis?
Marc Schwartz
marc_schwartz at me.com
Mon Aug 22 20:11:29 CEST 2011
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
More information about the R-help
mailing list