Hi, I would like to combine multiple xyplots into a single, multipanel display. Using R 3.0.1 in Ubuntu, I have used c() from latticeExtra to combine three plots, but the x-axis for two plots are on a log scale and the other is on a normal scale. I also have included equispace.log=FALSE to clean up the tick labels. However, when I try all of these, the x-axis scale of the first panel is used for all three. How do I keep different scales for the different panels? Here is an example: library(lattice) library(latticeExtra) response <- c(76, 14, 15, 44, 26, 19, 74, 123, 49, 8, 56, 17, 18) predictor1 <- c(107, 7, 25, 501, 64, 88, 344, 367, 379, 10, 66, 31, 32) predictor2 <- c(10, 9, 8, 10, 29, 27, 55, 48, 2, 6, 14, 10, 5) predictor3 <- c(67, 22, 66, 41, 72, 64, 69, 63, 64, 70, 60, 75, 78) pred1_plot <- xyplot(response ~ predictor1, scales = list(log = TRUE, equispaced.log = FALSE), panel = function(x, y, ...) { panel.xyplot(x, y, type = c("p", "r"), cex = 2) panel.text(x = log10(8), y = log10(120), labels = "(a)") } ) pred2_plot <- xyplot(response ~ predictor2, scales = list(log = TRUE, equispaced.log = FALSE), panel = function(x, y, ...) { panel.xyplot(x, y, type = c("p", "r"), cex = 2) panel.text(x = log10(2), y = log10(120), labels = "(b)") } ) pred3_plot <- xyplot(response ~ predictor3, scales = list(y = list(log = TRUE, equispaced.log = FALSE)), panel = function(x, y, ...) { panel.xyplot(x, y, type = c("p", "r"), cex = 2) panel.text(x = 22, y = log10(120), labels = "(c)") } ) all_plots <- c(pred1_plot, pred2_plot, pred3_plot, layout = c(3, 1), x.same = F) update(all_plots, xlab=c("Predictor 1","Predictor 2", "Predictor 3"), scales = list(y=list(log=T, equispaced.log=FALSE), x = c(list(log=T, equispaced.log=FALSE), list(log=T, equispaced.log=FALSE), list(log=F)))) update(all_plots, xlab=c("Predictor 1","Predictor 2", "Predictor 3"), scales = c(list(log = TRUE, equispaced.log = FALSE), list(log = TRUE, equispaced.log = FALSE), list(y=list(log=T, equispaced.log = FALSE)))) Any help is appreciated! Thanks, Jeff
No idea what I happening but does this give what you expect library(gridExtra) preds <- grid.arrange(pred1_plot,pred2_plot, pred3_plot, ncol=3) preds John Kane Kingston ON Canada> -----Original Message----- > From: stev0175 at gmail.com > Sent: Fri, 19 Jul 2013 22:18:47 -0500 > To: r-help at r-project.org > Subject: [R] Different x-axis scales using c() in latticeExtra > > Hi, > > I would like to combine multiple xyplots into a single, multipanel > display. Using R 3.0.1 in Ubuntu, I have used c() from latticeExtra > to combine three plots, but the x-axis for two plots are on a log > scale and the other is on a normal scale. I also have included > equispace.log=FALSE to clean up the tick labels. However, when I try > all of these, the x-axis scale of the first panel is used for all > three. How do I keep different scales for the different panels? > > Here is an example: > library(lattice) > library(latticeExtra) > response <- c(76, 14, 15, 44, 26, 19, 74, 123, 49, 8, 56, 17, 18) > predictor1 <- c(107, 7, 25, 501, 64, 88, 344, 367, 379, 10, 66, 31, 32) > predictor2 <- c(10, 9, 8, 10, 29, 27, 55, 48, 2, 6, 14, 10, 5) > predictor3 <- c(67, 22, 66, 41, 72, 64, 69, 63, 64, 70, 60, 75, 78) > > pred1_plot <- xyplot(response ~ predictor1, scales = list(log = TRUE, > equispaced.log = FALSE), > panel = function(x, y, ...) { > panel.xyplot(x, y, type = c("p", "r"), cex = 2) > panel.text(x = log10(8), y = log10(120), labels = "(a)") > } > ) > > pred2_plot <- xyplot(response ~ predictor2, scales = list(log = TRUE, > equispaced.log = FALSE), > panel = function(x, y, ...) { > panel.xyplot(x, y, type = c("p", "r"), cex = 2) > panel.text(x = log10(2), y = log10(120), labels = "(b)") > } > ) > > pred3_plot <- xyplot(response ~ predictor3, scales = list(y = list(log > = TRUE, equispaced.log = FALSE)), > panel = function(x, y, ...) { > panel.xyplot(x, y, type = c("p", "r"), cex = 2) > panel.text(x = 22, y = log10(120), labels = "(c)") > } > ) > > all_plots <- c(pred1_plot, pred2_plot, pred3_plot, layout = c(3, 1), > x.same = F) > update(all_plots, xlab=c("Predictor 1","Predictor 2", "Predictor 3"), > scales = list(y=list(log=T, equispaced.log=FALSE), x = c(list(log=T, > equispaced.log=FALSE), list(log=T, equispaced.log=FALSE), > list(log=F)))) > > update(all_plots, xlab=c("Predictor 1","Predictor 2", "Predictor 3"), > scales = c(list(log = TRUE, equispaced.log = FALSE), list(log = TRUE, > equispaced.log = FALSE), list(y=list(log=T, equispaced.log = FALSE)))) > > Any help is appreciated! > > Thanks, > Jeff > > ______________________________________________ > 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.____________________________________________________________ FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more!
David Winsemius
2013-Jul-20 16:50 UTC
[R] Different x-axis scales using c() in latticeExtra
On Jul 19, 2013, at 8:18 PM, Jeff Stevens wrote:> Hi, > > I would like to combine multiple xyplots into a single, multipanel > display. Using R 3.0.1 in Ubuntu, I have used c() from latticeExtra > to combine three plots, but the x-axis for two plots are on a log > scale and the other is on a normal scale. I also have included > equispace.log=FALSE to clean up the tick labels. However, when I try > all of these, the x-axis scale of the first panel is used for all > three. How do I keep different scales for the different panels? > > Here is an example: > library(lattice) > library(latticeExtra) > response <- c(76, 14, 15, 44, 26, 19, 74, 123, 49, 8, 56, 17, 18) > predictor1 <- c(107, 7, 25, 501, 64, 88, 344, 367, 379, 10, 66, 31, 32) > predictor2 <- c(10, 9, 8, 10, 29, 27, 55, 48, 2, 6, 14, 10, 5) > predictor3 <- c(67, 22, 66, 41, 72, 64, 69, 63, 64, 70, 60, 75, 78) > > pred1_plot <- xyplot(response ~ predictor1, scales = list(log = TRUE, > equispaced.log = FALSE), > panel = function(x, y, ...) { > panel.xyplot(x, y, type = c("p", "r"), cex = 2) > panel.text(x = log10(8), y = log10(120), labels = "(a)") > } > ) > > pred2_plot <- xyplot(response ~ predictor2, scales = list(log = TRUE, > equispaced.log = FALSE), > panel = function(x, y, ...) { > panel.xyplot(x, y, type = c("p", "r"), cex = 2) > panel.text(x = log10(2), y = log10(120), labels = "(b)") > } > ) > > pred3_plot <- xyplot(response ~ predictor3, scales = list(y = list(log > = TRUE, equispaced.log = FALSE)), > panel = function(x, y, ...) { > panel.xyplot(x, y, type = c("p", "r"), cex = 2) > panel.text(x = 22, y = log10(120), labels = "(c)") > } > ) > > all_plots <- c(pred1_plot, pred2_plot, pred3_plot, layout = c(3, 1), x.same = F) > update(all_plots, xlab=c("Predictor 1","Predictor 2", "Predictor 3"), > scales = list(y=list(log=T, equispaced.log=FALSE), x = c(list(log=T, > equispaced.log=FALSE), list(log=T, equispaced.log=FALSE), > list(log=F)))) > > update(all_plots, xlab=c("Predictor 1","Predictor 2", "Predictor 3"), > scales = c(list(log = TRUE, equispaced.log = FALSE), list(log = TRUE, > equispaced.log = FALSE), list(y=list(log=T, equispaced.log = FALSE)))) > > Any help is appreciated!I assume there was a notice o your console that there were warnings, right? You should offer the full texts of warnings and error messages. Here the full text of the first and second warnings:> warnings()[1:2]$`log scales cannot be changed via 'update'` update.trellis(all_plots, xlab = c("Predictor 1", "Predictor 2", "Predictor 3"), scales = c(list(log = TRUE, equispaced.log = FALSE), list(log = TRUE, equispaced.log = FALSE), list(y = list(log = T, equispaced.log = FALSE)))) $`'x' is NULL so the result will be NULL` rep(scales[[nm]], length.out = 2) The first one is telling you why the results should be different than you expect. I'm not entirely sure what the second one is telling you, but it doesn't sound good. -- David Winsemius Alameda, CA, USA
Possibly Parallel Threads
- problem with predict(mboost,...)
- Logistic regression goodness of fit tests
- strategy to iterate over repeated measures/longitudinal data
- ANOVA test to decide whether to use multiple linear regression or linear mixed effects model
- lattice::panel.levelplot.raster too picky with unequal spacing