I would like to change the binwidth in a faceted histogram.
Here is an example of:
## I create some data
a <- data.frame(val=rnorm(1000, 0, 10), label="a")
b <- data.frame(val=rgamma(1000, 1, 20), label="b")
dat <- rbind(a,b)
# The v graph looks nice...
v <- ggplot(dat=dat, aes(x=val, y=..ncount..)) + geom_histogram() +
facet_grid(.~ label, scales="free")
print(v)
## ... but when I am trying to change the binwidth, the graph looks ugly.
u <- ggplot(dat=dat, aes(x=val, y=..ncount..)) +
geom_histogram(binwidth=1/50) + facet_grid(.~ label, scales="free")
print(u)
The website says that binwidth defaults to 1/30 of the range. As graph
v shows, range applies to each faceted graph, while the value of
binwidth=1/50 in graph u applies to two both histograms. (Binwidth
also doesn't take vectors; I tried that.)
The question is: How can I change the binwidth to 1/50 of the range
for each faceted graph?
Thanks so much.
Toby
PS: I am new to ggplot; so forgive me if the answer is trivial.
Currently, all panels in a layer have to have the same parameters
(mainly because I can't see any nice way of specifying varying
parameters). You should be able to work around the problem by using
separate layers:
ggplot(dat=dat, aes(x=val, y=..ncount..)) +
geom_histogram(data = subset(data, label == "a"), binwidth=1/50) +
geom_histogram(data = subset(data, label == "b"), binwidth=1/10) +
facet_grid(.~ label, scales="free")
However I'm not on a computer with R at the moment, so I can't double
check that this actually works.
Hadley
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2