[R] Barplot with grouping x axis and count data

hadley wickham h.wickham at gmail.com
Mon Mar 3 21:04:43 CET 2008


On Mon, Mar 3, 2008 at 11:01 AM, **linda** <berichtjeaanlinda at gmail.com> wrote:
>
>  Hello,
>  I am trying to make a barplot with nested count data which is build like
>  this: first there are several birds (n)laying 3 clutches composed of 2 eggs
>  half of the second and third clutch received treatment and this treatment
>  was tested to influence sex of offspring. I want a barplot showing counts
>  for male and female for every egg of every clutch. can someone tell me what
>  to do? I drew a table of how i wanted it to look with:
>  ftable(sex,clutch,egg,treat) giving:
>
>  clutch   egg   treat    #females #males
>  1          1        0            14       21
>                       1           5         2
>             2        0            25       24
>                      1            3         43
>  2          1        0            23       43
>                      1            23       5
>             2       0            43        6
>                      1            54        1
>  3 etc
>
>  I would want to have clutch egg and treat all on the xaxis but not in
>  separate bars but nested within eachother just like the table. Can someone
>  tell me how to deal with this problem?
>
>  thank you,
>  Linda

Here's one approach:

library(ggplot2)
qplot(egg, geom="bar", colour=treat, facets= clutch ~ sex)

Otherwise, you might try providing a minimal reproducible dataset, and
describe more clearly the graphic that you want.

Hadley

-- 
http://had.co.nz/



More information about the R-help mailing list