[R] Different x-axis scales using c() in latticeExtra

Jeff Stevens stev0175 at gmail.com
Sat Jul 20 05:18:47 CEST 2013


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



More information about the R-help mailing list