[R] Simple lattice question

Peter Ehlers ehlers at ucalgary.ca
Fri Apr 1 14:45:45 CEST 2011


Ruben,

One more thing you might try is to add a 'size' component to
the lines list. The default is size=5, but since you have
enought space in the plot, try size=8 or 9; the line types
will show up more clearly:

  ....
      lines=list(pch=1:4, lty=1:4, type='b', size=8),
      ....

Peter Ehlers

On 2011-03-31 23:28, Rubén Roa wrote:
>> -----Mensaje original-----
>> De: Peter Ehlers [mailto:ehlers at ucalgary.ca]
>> Enviado el: jueves, 31 de marzo de 2011 18:09
>> Para: Rubén Roa
>> CC: r-help at r-project.org
>> Asunto: Re: [R] Simple lattice question
>>
>> On 2011-03-31 06:58, Rubén Roa wrote:
>>> Thanks Peters!
>>>
>>> Just a few minor glitches now:
>>>
>>> require(lattice)
>>> data<-
>> data.frame(SP=sort(rep(as.factor(c('A','B','C','D','E')),12)),
>>>                      x=rpois(60,10),
>>>                      y=rep(c(rep(0,4),rep(10,4),rep(20,4)),5),
>>>                      z=rep(1:4,15))
>>>
>> xyplot(x~y|SP,data=data,groups=z,layout=c(2,3),pch=1:4,lty=1:4
> ,col='black',type='b',
>>>          key=list(x = .65, y = .75, corner = c(0, 0), points=TRUE,
>>>                     lines=TRUE, pch=1:4, lty=1:4, type='b',
>>>                     text=list(lab = as.character(unique(data$z)))))
>>>
>>> I have an extra column of symbols on the legend,
>>>
>>> and,
>>>
>>> would like to add a title to the legend. Such as 'main' for plots.
>>>
>>> Any suggestions?
>>
>> for key(), make 'lines' into a list:
>>
>>    xyplot(x~y|SP,data=data,groups=z,layout=c(2,3),
>>           pch=1:4,lty=1:4,col='black',type='b',
>>           key=list(x = .65, y = .75, corner = c(0, 0),
>>                    title="title here", cex.title=.9, lines.title=3,
>>                    lines=list(pch=1:4, lty=1:4, type='b'),
>>                    text=list(lab = as.character(unique(data$z)))))
>>
>> Peter Ehlers
>
> ... that works. Thanks Peter (sorry I misspelled your name b4). The clean code is now:
>
> require(lattice)
> data<- data.frame(SP=sort(rep(as.factor(c('A','B','C','D','E')),12)),
>                     x=rpois(60,10),
>                     y=rep(c(rep(0,4),rep(10,4),rep(20,4)),5),
>                     z=rep(1:4,15))
> xyplot(x~y|SP,data=data,groups=z,layout=c(2,3),pch=1:4,lty=1:4,col='black',type='b',
>         key=list(x = .65, y = .75, corner = c(0, 0),
>                    lines=list(pch=1:4, lty=1:4, type='b'),
>                    title=expression(CO^2),
>                    text=list(lab = as.character(unique(data$z)))))
>
> David's code works too (thanks to you too!) and is somewhat shorter
>
> xyplot(x~y|SP, data=data,groups=z, layout=c(2,3), par.settings=simpleTheme(pch=1:4,lty=1:4,col='black'), type="b",
>         auto.key = list(x = .6, y = .7, lines=TRUE, corner = c(0, 0)))
>
> but the lines and symbols are on different columns, and the line types look as if they were in bold.
>
> Rubén
>
>
> ____________________________________________________________________________________
>
> Dr. Rubén Roa-Ureta
> AZTI - Tecnalia / Marine Research Unit
> Txatxarramendi Ugartea z/g
> 48395 Sukarrieta (Bizkaia)
> SPAIN
>
>



More information about the R-help mailing list