Ben Bimber
2010-Mar-25 15:52 UTC
[R] Basic graphs: something like groups, but where each plot has independent axis?
I am trying to graph weight data for our colony. We a data frame with Animal, Weight and Date. I'd like to display this data a series of simple xyplots. We only need to display these plots together, we do not need to make comparisons between animals. Each animal has been weighted over a different time period, so we do not want the same range for each X axis. Using the following, I can create one plot per animal: size <- length(unique(data$id)) xyplot(weight ~ date | id, data=data, #type="o", layout=c(1,size), xlab="Date", ylab="Weight" ); However, they share a common X axis. Is it possible to avoid this? In other words, I might want the first animal's plot to extend from 2008-01-01 through 2009-05-04, while the second plot extends from 2007-02-04 through 2010-01-01. Also, can I introduce more whitespace between each plot? Thank you for any help. [[alternative HTML version deleted]]
Sharpie
2010-Mar-25 16:26 UTC
[R] Basic graphs: something like groups, but where each plot has independent axis?
Ben Bimber wrote:> > I am trying to graph weight data for our colony. We a data frame with > Animal, Weight and Date. I'd like to display this data a series of simple > xyplots. We only need to display these plots together, we do not need to > make comparisons between animals. Each animal has been weighted over a > different time period, so we do not want the same range for each X axis. > > > Using the following, I can create one plot per animal: > > size <- length(unique(data$id)) > xyplot(weight ~ date | id, > data=data, > #type="o", > layout=c(1,size), > xlab="Date", > ylab="Weight" > ); > > However, they share a common X axis. Is it possible to avoid this? In > other words, I might want the first animal's plot to extend from > 2008-01-01 > through 2009-05-04, while the second plot extends from 2007-02-04 through > 2010-01-01. > > Also, can I introduce more whitespace between each plot? > > Thank you for any help. >You can do this in ggplot2 using facet_wrap( ~ id, scales = "free_x" ): colonyPlot <- qplot( date, weight, data = data, xlab = "Date", ylab = "Weight" ) + facet_wrap( ~ id, scales = "free_x" ) + theme_bw() print( colonyPlot ) Not sure about hot to do it using xyplot though. The following website may help for ggplot2: http://had.co.nz/ggplot2/facet_wrap.html Good luck! -Charlie ----- Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://n4.nabble.com/Basic-graphs-something-like-groups-but-where-each-plot-has-independent-axis-tp1690870p1690937.html Sent from the R help mailing list archive at Nabble.com.
Dylan Beaudette
2010-Mar-25 16:37 UTC
[R] Basic graphs: something like groups, but where each plot has independent axis?
On Thursday 25 March 2010, Ben Bimber wrote:> I am trying to graph weight data for our colony. We a data frame with > Animal, Weight and Date. I'd like to display this data a series of simple > xyplots. We only need to display these plots together, we do not need to > make comparisons between animals. Each animal has been weighted over a > different time period, so we do not want the same range for each X axis. > > > Using the following, I can create one plot per animal: > > size <- length(unique(data$id)) > xyplot(weight ~ date | id, > data=data, > #type="o", > layout=c(1,size), > xlab="Date", > ylab="Weight" > ); > > However, they share a common X axis. Is it possible to avoid this? In > other words, I might want the first animal's plot to extend from 2008-01-01 > through 2009-05-04, while the second plot extends from 2007-02-04 through > 2010-01-01.Hi, Be sure to see the scales argument in the manual page for xyplot(). Here is one approach to getting different scales on the x-axis: xyplot(weight ~ date | id, data=data, layout=c(1,size), xlab="Date", ylab="Weight", scales=list(x=list(relation="free")) ) I think that there is a 'space' argument to most of the lattice plotting functions, but be sure to check the manual page. Another great resource is this website: http://lmdvr.r-forge.r-project.org/figures/figures.html Cheers, Dylan> Also, can I introduce more whitespace between each plot? > > Thank you for any help. > > [[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.-- Dylan Beaudette Soil Resource Laboratory http://casoilresource.lawr.ucdavis.edu/ University of California at Davis 530.754.7341