Creating a flat legend 'grob' for lattice xyplot

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating a flat legend 'grob' for lattice xyplot

Mark
Hi,

I want my xyplot legend to be flat, not tall, and there seems to be no way for xyplot's auto.key and key elements to do this: I tried many, many permutations of what I could find in the archives and reading the documentation.  If there there's a way to make it flat, please tell me what the magic incantation is.

Here's a simple example of what I like to see.  The xyplot will be a multi-panelled one with a single,
flat legend below.  It seems the xyplot's legend element is the way to go -- the option I haven't tried because I don't know what or how to create a grob of this kind.  Where to start?

xyplot(1~1)
legend(0.15,-0.125, bty='n',pch=rep(c(15,17),2),col=c('brown','green','blue','red'),ncol=4,
          legend=c('How','to make','this into', 'a grob?'))

Thanks!

Reply | Threaded
Open this post in threaded view
|

Re: Creating a flat legend 'grob' for lattice xyplot

Gesmann, Markus
Hi Mark,

I believe the argument you are looking for is column not ncol.
Try the following:

library(lattice)
xyplot(1~1,
auto.key=list(
bty='n',
pch=rep(c(15,17),2),
col=c('brown','green','blue','red'),
columns=4,      
text=c('How','to make','this into', 'a grob?'),
space="top"
))

 
Regards

Markus

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Mark
Sent: 27 July 2011 18:32
To: [hidden email]
Subject: [R] Creating a flat legend 'grob' for lattice xyplot

Hi,

I want my xyplot legend to be flat, not tall, and there seems to be no way for xyplot's auto.key and key elements to do this: I tried many, many permutations of what I could find in the archives and reading the documentation.  If there there's a way to make it flat, please tell me what the magic incantation is.

Here's a simple example of what I like to see.  The xyplot will be a multi-panelled one with a single, flat legend below.  It seems the xyplot's legend element is the way to go -- the option I haven't tried because I don't know what or how to create a grob of this kind.  Where to start?

xyplot(1~1)
legend(0.15,-0.125,
bty='n',pch=rep(c(15,17),2),col=c('brown','green','blue','red'),ncol=4,
          legend=c('How','to make','this into', 'a grob?'))

Thanks!



--
View this message in context: http://r.789695.n4.nabble.com/Creating-a-flat-legend-grob-for-lattice-xyplot-tp3699235p3699235.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[hidden email] 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.
**********************************************************************
The information in this E-Mail and in any attachments is...{{dropped:27}}

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Creating a flat legend 'grob' for lattice xyplot

David Winsemius
In reply to this post by Mark

On Jul 27, 2011, at 1:31 PM, Mark wrote:

> Hi,
>
> I want my xyplot legend to be flat, not tall, and there seems to be  
> no way
> for xyplot's auto.key and key elements to do this: I tried many, many
> permutations of what I could find in the archives and reading the
> documentation.  If there there's a way to make it flat, please tell  
> me what
> the magic incantation is.
>
> Here's a simple example of what I like to see.  The xyplot will be a
> multi-panelled one with a single,
> flat legend below.  It seems the xyplot's legend element is the way  
> to go --
> the option I haven't tried because I don't know what or how to  
> create a grob
> of this kind.  Where to start?
>
> xyplot(1~1)   # a lattice function
> legend(0.15,-0.125,    # a base graphics function
> bty='n',pch=rep(c(15,17),
> 2),col=c('brown','green','blue','red'),ncol=4,
>          legend=c('How','to make','this into', 'a grob?'))

It is possible to define a legend object inside xyplot but using the  
base graphics legend() is NOT how it is done. You should provide a  
sample data.frame and someone will show you how to do it. The example  
in Sarkar's Lattice book that does it uses barchart and specifies  
auto.key with a columns= argument. It's fig 10.2 and you can find the  
examples on the website. It's also described in the key section of ?
xyplot .... I just looked.

--
David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Creating a flat legend 'grob' for lattice xyplot

Mark
This post was updated on .
In reply to this post by Gesmann, Markus
Hi Markus,

That's almost it!  So ncol and column do the same thing in different functions... gah!

Because my real use of xyplot I override the default plotting colors and character, autokey doesn't 'know' this, so they don't match.

So the addition of the par.settings element is needed (from another e-mail):

xyplot(1~1,
auto.key=list(
bty='n',
columns=4,      
text=c('How','to make','this into', 'a grob?'),
space="top",
par.settings=simpleTheme(pch=rep(c(15,17),2),col=c('brown','green','blue','red')
))

My legend is flat and color coordinated now.

Thank you very much!