[R] ggplot2: can one have separate ylim for each facet?

hadley wickham h.wickham at gmail.com
Mon Nov 17 23:55:28 CET 2008


On Mon, Nov 17, 2008 at 3:49 PM, Etches Jacob <jacob.etches at utoronto.ca> wrote:
> In lattice
>
> #toy data
> library(ggplot2)
> library(lattice)
> x <- rnorm(100)
> y <- rnorm(100)
> k <- sample(c("Weak","Strong"),100,replace=T)
> j <- sample(c("Tall","Short"),100,replace=T)
> w <- data.frame(x,y,j,k)
>
> xyplot(y~x|j+k,scales=list(y=list(relation="free")))
>
> will give you a scale in each subplot with a range equal to the range of y
> within each subplot.
>
> Is this possible using ggplot2?
>
> qplot(x,y,data=w) + facet_grid(j~k) + ylim(-2,2)
>
> produces a plot with the same range in each subplot.  Can the lattice
> behaviour be reproduced in ggplot2?

Not yet, but in the next version (to be released within the week),
you'll be able to do:

qplot(x,y,data=w) + facet_grid(j~k, scales = "free_y") + ylim(-2,2)

Hadley

-- 
http://had.co.nz/



More information about the R-help mailing list