Re: [R] Barplot with grouping x axis and count data

From: hadley wickham <h.wickham_at_gmail.com>
Date: Mon, 03 Mar 2008 14:04:43 -0600

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/

______________________________________________
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.
Received on Mon 03 Mar 2008 - 20:06:44 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 03 Mar 2008 - 20:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive