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

Jeff Stevens stev0175 at gmail.com
Sun Jul 21 22:59:01 CEST 2013


Thanks, David.  The warnings occur after the true problem of trying to
plot the three graphs with different scales.  I should have stopped
the example after assigning all_plots <- c(...), then plotted it (and
left out the update statements).  If you do this, the x-axes do not
maintain their scales.

But I take your point that I should have paid more attention to the warnings!

Thanks,
Jeff



On Sat, Jul 20, 2013 at 11:50 AM, David Winsemius
<dwinsemius at comcast.net> wrote:
>
> 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
>



More information about the R-help mailing list