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

Jeff Stevens stev0175 at gmail.com
Sun Jul 21 22:53:50 CEST 2013


Many thanks, Felix.  Though, it seems like the x.same option should
allow this: "if TRUE, set the x scale relation to "same" and
recalculate panel limits using data from all panels. Otherwise, the x
scales in each panel will be as they were in the original objects (so
in general not the same), the default behaviour."  Or does this just
refer to different axis ranges on the same type of scale?

By the way, the grid.arrange feature from gridExtra seems to produce
the same output as plot.trellis using the split option.  Is there an
advantage to using grid.arrange over plot.trellis?  Also, do you have
pointers to documentation that would help me alter the plot.trellis
output to look more like the c() output (e.g., remove horizontal space
between plots and make sure plots have consistent widths?

Thanks,
Jeff

On Sat, Jul 20, 2013 at 6:45 PM, Felix Andrews <felix at nfrac.org> wrote:
> latticeExtra's c() can not combine logarithmic with linear x scales,
> I'm afraid.  I would recommend displaying each separate plot on one
> page using plot.trellis() or the gridExtra function that John Kane
> mentioned.
>
> Cheers
> Felix
>
>
> On 21 July 2013 02:50, 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
>>
>> ______________________________________________
>> 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.
>
>
>
> --
> Felix Andrews / 安福立
> http://www.neurofractal.org/felix/



More information about the R-help mailing list