[R] Setting scales for ggplot2 with facets

Tom Hiatt tomhiatt at gmail.com
Fri Jun 24 09:54:17 CEST 2011


Hi Sven,

Not sure if you're still having this problem, but I was as well and googled
into your post. I didn't find a great answer either, but the workaround I'm
using is some dummy points or lines with alpha=0 so they don't show up (ie
geom_hline(yintercept=0, alpha=0)). I suppose the same could be added to
your dataset and plotted as another layer.

Tom


Sven Laur wrote:
> 
> Sorry,  I was too vague in my initial question. To make it clearer I  
> included the following example:
> 
> 
> tmp <- data.frame(y=runif(10), x=gl(2,5), class=gl(2,5))
> p <- ggplot(data = tmp)
> p <- p + geom_point(aes(y=y, x=x))
> p <- p + facet_wrap(~ class, scales = "free")
> p <- p + ylim(0, 1)
> p
> 
> This code draws two facets each having 5 points.  As explained before,  
> I would like to
> control y-range of both facet plots. For clarity, say that ylim = c(0,  
> 0.5) for the facet "1"
> and ylim = c(0.5, 3) for the facet "2". How should I do it?
> 
> As a quick hack I could, eliminate outliers for both facets, i.e.  
> write lines
> 
> tmp <- cbind(subset(tmp, class == 1 & y <= 0.5), subset(tmp, class ==  
> 2 & y >= 0.5))
> 
> before plotting but this would work only for simple geometrics. For  
> geom_boxplot
> it would skew the distribution.
> 
> 
> Swen Laur
> 
> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.
> 


--
View this message in context: http://r.789695.n4.nabble.com/Setting-scales-for-ggplot2-with-facets-tp2535910p3621914.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list