[R] ggplot2 axis scales

From: Felipe Carrillo <mazatlanmexico_at_yahoo.com>
Date: Sat, 28 Jun 2008 13:22:25 -0700 (PDT)


 Hi all:
Was this question ever answered?

#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" ) + scale_y_continuous(limits=c(NA,NA))

#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") )

Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA



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. Received on Sat 28 Jun 2008 - 20:26:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 29 Jun 2008 - 01:31:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive