[R] Two-levels labels on x-axis?

Joshua Wiley jwiley.psych at gmail.com
Mon Aug 22 20:07:17 CEST 2011


Hi Sébastien,

Not sure about an elegant, general way but here is something quick and dirty:

p <- barplot(matrix(1:8, 2))
axis(1, at = p, labels = letters[1:4])
axis(1, at = c(mean(p[1:2]), mean(p[3:4])), labels = paste("\n",
LETTERS[1:2]), padj = 1)

Cheers,

Josh



On Mon, Aug 22, 2011 at 10:14 AM, Sébastien Vigneau
<sebastien.vigneau at gmail.com> 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
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list