Hey there!
I'm trying to produce a plot showing the effect of a tranformation of my response variable. I do this by plotting histograms of the raw and transformed data. The default, range/30 gives too many bins. But setting the binwidth in the geom_histogram call sets a universal binwidth across both facets, which is not the result I want.
How do I set binwidth according to a factor? (In this case, the same factor that I am facetting by.)
Minimal working example, with some silly data:
##
library(ggplot2)
library(reshape)
data <- seq(from=0,to=0.2,length=100) #raw response
trans <- log(data/(1-data)) #logit transformed response
frame <- melt(data.frame(data,trans)) #collect
ggplot(data = frame, aes(x=value)) + geom_histogram() + facet_wrap(~variable, scales = "free") #default - too many bins, but they are nicel adjusted for each facet.
ggplot(data = frame, aes(x=value)) + geom_histogram(binwidth = diff(range(dat$value))/5) + facet_wrap(~variable, scales = "free") #what I want - but I want the binwidth to be 1/5 of the range *within each facet*
##
Thanks in advance!
Benjamin