[R] trellis/lattice: How to plot 4 panels with the same x-scale but different y-scales?
Deepayan Sarkar
deepayan.sarkar at gmail.com
Thu May 6 15:09:57 CEST 2010
On Thu, May 6, 2010 at 6:24 PM, Marius Hofert <m_hofert at web.de> wrote:
> Thanks, Deepayan.
>
> Is it at least possible to increase the space between the panels in the following plot?:
>
> library(lattice)
> x=rep(c(1,2,3),4) # x values
> y=1:12 # y values
> z=rep(1:4,each=3) # panel number
> xyplot(y~x|z,type="l",aspect=1,layout=c(2,2),
> scales=list(relation="free",alternating=c(1,1),tck=c(1,0)),
> panel=function(...){
> panel.xyplot(...,col=1)
>
> }
> )
Sure, add
par.settings = list(layout.widths = list(axis.panel = 2))
(similarly layout.heights for vertical gap).
-Deepayan
>
> On 2010-05-06, at 13:53 , Deepayan Sarkar wrote:
>
>> On Thu, May 6, 2010 at 12:16 PM, Marius Hofert <m_hofert at web.de> wrote:
>>> Dear R experts,
>>>
>>> I have four plots I would like to plot attached to each other (in panels).
>>> All plots have the same x-scale, but different y-scales. The example below shows
>>> pretty much what I would like to have, except that for the two plots in the
>>> "second column" (of this 2x2 plot-matrix), I would like to have the y-ticks
>>> shown on the right side such that the four plot panels are attached to each other/glued
>>> together. How can I achieve this?
>>
>> There is no easy way.
>>
>> For the first step of a difficult way, see ?axis.default
>>
>> -Deepayan
>>
>>
>>> I found a solution for a 2x1 matrix in the R-help archive, but this problem here is different.
>>>
>>> Cheers,
>>>
>>> Marius
>>>
>>> Ps: I guess the "scales=..." should somehow go inside the panel function, so that
>>> the panel number tells the "alternating"-argument where it has to print the ticks.
>>>
>>> library(lattice)
>>> x=rep(c(1,2,3),4) # x values
>>> y=1:12 # y values
>>> z=rep(1:4,each=3) # panel number
>>> xyplot(y~x|z,type="l",aspect=1,layout=c(2,2),
>>> scales=list(y=list(relation="free"),alternating=c(1,1),tck=c(1,0)),
>>> panel=function(...){
>>> panel.xyplot(...,col=1)
>>>
>>> }
>>> )
>>> ______________________________________________
>>> 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.
>>>
>
>
More information about the R-help
mailing list