Karl Ove Hufthammer
2007-Jul-16 12:04 UTC
[R] Different axis limits for each facet in ggplot2
Hi! Is it possible to have different axis limit for each facet in a ggplot2 plot? Here is an example: -------------------------------------------------------------- library(ggplot2) x=seq(-10,10,.1) y=cos(x) z=sin(x)*10 dat=melt(data.frame(x,y,z), id.var="x") qplot( x, value, data=dat, facets=variable~., geom="line" ) -------------------------------------------------------------- Both the x and y axes are now the same for both facets. But since the ranges of the 'y' and the 'z' variable differ so much, I would prefer their y axes to be different. This is easy to do in 'lattice': -------------------------------------------------------------- library(lattice) xyplot( value~x | variable, data=dat, type="l", layout=c(1,2), scale=list(y="free") ) -------------------------------------------------------------- Is it possible to do this in 'ggplot2' too? I would have thought that + scale_y_continuous(limits=c(NA,NA)) would work, but this sets the 'y' axis to cover the range of 'y' and 'z' *combined* (which is very sensible as a default, but not what I would prefer here). -- Karl Ove Hufthammer
On 7/16/07, Karl Ove Hufthammer <Karl.Hufthammer at math.uib.no> wrote:> Hi! > > Is it possible to have different axis limit for each facet in a ggplot2 > plot? Here is an example:Not yet, although it is on the to do list.> -------------------------------------------------------------- > library(ggplot2) > > x=seq(-10,10,.1) > y=cos(x) > z=sin(x)*10One crude way to get around it is: df <- data.frame(x,y,z) df <- rescaler(df) - ie. scale all variables to common scales Hadley
Karl Ove Hufthammer
2007-Jul-17 08:32 UTC
[R] Different axis limits for each facet in ggplot2
hadley wickham:>> Is it possible to have different axis limit for each facet in a ggplot2 >> plot? Here is an example: > > Not yet, although it is on the to do list.Thanks for the answer. I?ll be looking forward to the next version(s) then. :) -- Karl Ove Huftammer