foo <- structure(list(year = c(2009, 2009, 2009, 2010, 2010, 2010, 2011,
2011, 2011), grade = c(6, 7, 8, 6, 7, 8, 6, 7, 8), readprob = c(0.100029,
0.0996918, 0.0765892, 0.124111, 0.0777718, 0.0663743, 0.120688,
0.110797, 0.0594606)), .Names = c("year", "grade", "readprob"
), class = "data.frame", row.names = c("2909", "2910", "2911",
"2912", "2913", "2914", "2915", "2916", "2917"))
The code I'm running is:
ggplot(data=foo, aes(x=grade, y=100*mathprob))+
geom_bar(stat="identity")+
scale_x_discrete(name="Probability of Exceeding Standards",
limits=c(6, 8), breaks=c(6, 7, 8), labels=c(6, 7, 8), drop=T) +
scale_y_continuous(name="Probability of Exceeding Standards",
limits=c(0, 35))+
opts(title="Probability of Exceeding Standards in Grade 8 Math")+
facet_grid(. ~ year)
I expected to get three bars, one for each grade (6, 7, 8) approximately
centered in each panel. But what I get is three bars jammed in on the
right, with blank space where bars for the non-existent grades 1:5 would
be.
Any idea why this should be so?
TIA.
--
Stuart Luppescu
CCSR University of Chicago
slu <at> ccsr <dot> uchicago <dot> edu
ggplot(data=foo, aes(x=grade, y=100*readprob))+
geom_bar(stat="identity")+
scale_x_discrete(name="Probability of Exceeding Standards", limits=c(6,
8), breaks=c(6, 7, 8), labels=c(6, 7, 8), drop=T) +
scale_y_continuous(name="Probability of Exceeding Standards",
limits=c(0, 35))+
opts(title="Probability of Exceeding Standards in Grade 8 Reading")+
facet_grid(. ~ year)
You just need to make the grade variable a factor. So....
On Wed, Mar 28, 2012 at 3:23 PM, Stuart Luppescu <s...@ccsr.uchicago.edu> wrote:
> Hello, I'm trying to plot bars but they are disobeying my limits commands.
> (Insolent bars!) Here is the data:
>
> foo <- structure(list(year = c(2009, 2009, 2009, 2010, 2010, 2010, 2011,
> 2011, 2011), grade = c(6, 7, 8, 6, 7, 8, 6, 7, 8), readprob = c(0.100029,
> 0.0996918, 0.0765892, 0.124111, 0.0777718, 0.0663743, 0.120688,
> 0.110797, 0.0594606)), .Names = c("year", "grade", "readprob"
> ), class = "data.frame", row.names = c("2909", "2910", "2911",
> "2912", "2913", "2914", "2915", "2916", "2917"))
See:
str(foo)
foo$grade <- factor(foo$grade)
>
> The code I'm running is:
> ggplot(data=foo, aes(x=grade, y=100*mathprob))+
> geom_bar(stat="identity")+
> scale_x_discrete(name="Probability of Exceeding Standards", limits=c(6, 8),
> breaks=c(6, 7, 8), labels=c(6, 7, 8), drop=T) +
> scale_y_continuous(name="Probability of Exceeding Standards", limits=c(0,
> 35))+
> opts(title="Probability of Exceeding Standards in Grade 8 Math")+
> facet_grid(. ~ year)
ggplot2 does a pretty nice job of setting the limits on plots so I
altered you code just a little but I think this might be what you are
looking for:
ggplot(data=foo, aes(x=grade, y=100*readprob))+
geom_bar(stat="identity")+
scale_x_discrete(name="Probability of Exceeding Standards") +
scale_y_continuous(name="Probability of Exceeding Standards")+
opts(title="Probability of Exceeding Standards in Grade 8 Math")+
facet_grid(. ~ year)
HTH,
Sam
>
> I expected to get three bars, one for each grade (6, 7, 8) approximately
> centered in each panel. But what I get is three bars jammed in on the right,
> with blank space where bars for the non-existent grades 1:5 would be.
>
> Any idea why this should be so?
>
> TIA.
>
> --
> Stuart Luppescu
> CCSR University of Chicago
> slu <at> ccsr <dot> uchicago <dot> edu
>
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
Awesome! Thanks, Sam.