Quantcast

Legends in xyplot

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

Legends in xyplot

Ravi Varadhan
Hi,

 

How can I add legends in the "xyplot" function, in the "lattice" library?
Here is a simulation example:

 

x <- runif(90)

z <- sample(1:3, 90, rep=T)

y <- rnorm(90, mean = x^2 + z, sd=1)

 

library(lattice)

trellis.par.set(col.whitebg())

xyplot(y ~x, groups=as.factor(z), type = c('p', 'smooth'), span = .67)

 

Thanks in advance,

Ravi.

 


        [[alternative HTML version deleted]]

______________________________________________
[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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Legends in xyplot

Uwe Ligges
See ?xyplot and its argument "legend".

Uwe Ligges




Ravi Varadhan wrote:

> Hi,
>
>  
>
> How can I add legends in the "xyplot" function, in the "lattice" library?
> Here is a simulation example:
>
>  
>
> x <- runif(90)
>
> z <- sample(1:3, 90, rep=T)
>
> y <- rnorm(90, mean = x^2 + z, sd=1)
>
>  
>
> library(lattice)
>
> trellis.par.set(col.whitebg())
>
> xyplot(y ~x, groups=as.factor(z), type = c('p', 'smooth'), span = .67)
>
>  
>
> Thanks in advance,
>
> Ravi.
>
>  
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [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

______________________________________________
[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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Legends in xyplot

Ravi Varadhan
Hi Uwe,

I am aware of the "legend" option in xyplot, but I can't figure out how to
make it work.  In particular, I do not understand how to use "legend" along
with the "key" argument. For my example, I would like to have a legend box
inside the plotting frame to indicate the 3 different smoothed curves.  
Can someone give me a simple example or show how to do this for my example?

Thanks very much,
Ravi.

> -----Original Message-----
> From: Uwe Ligges [mailto:[hidden email]]
> Sent: Tuesday, January 17, 2006 3:08 AM
> To: Ravi Varadhan
> Cc: [hidden email]
> Subject: Re: [R] Legends in xyplot
>
> See ?xyplot and its argument "legend".
>
> Uwe Ligges
>
>
>
>
> Ravi Varadhan wrote:
>
> > Hi,
> >
> >
> >
> > How can I add legends in the "xyplot" function, in the "lattice"
> library?
> > Here is a simulation example:
> >
> >
> >
> > x <- runif(90)
> >
> > z <- sample(1:3, 90, rep=T)
> >
> > y <- rnorm(90, mean = x^2 + z, sd=1)
> >
> >
> >
> > library(lattice)
> >
> > trellis.par.set(col.whitebg())
> >
> > xyplot(y ~x, groups=as.factor(z), type = c('p', 'smooth'), span = .67)
> >
> >
> >
> > Thanks in advance,
> >
> > Ravi.
> >
> >
> >
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [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

______________________________________________
[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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Legends in xyplot

Deepayan Sarkar
On 1/17/06, Ravi Varadhan <[hidden email]> wrote:
> Hi Uwe,
>
> I am aware of the "legend" option in xyplot, but I can't figure out how to
> make it work.  In particular, I do not understand how to use "legend" along
> with the "key" argument. For my example, I would like to have a legend box
> inside the plotting frame to indicate the 3 different smoothed curves.
> Can someone give me a simple example or show how to do this for my example?

Here's a modified version of an example in demo(lattice):

xyplot(Petal.Length ~ Petal.Width, data = iris,
       groups = Species,
       type = c("p", "smooth"), span=.75,
       auto.key =
       list(title = "Iris Data",
            x = .15, y=.85, corner = c(0,1),
            border = TRUE, lines = TRUE))

-Deepayan

______________________________________________
[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
Loading...