Hi,
I have a densityplot like this:
x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6))
f =
sample(c("A","B","C","D","E"),300,replace=TRUE)
df=data.frame(x,f)
library(lattice)
attach(df)
densityplot(~x, groups=f)
And I want to add a legend with the colours for the factors. How can I do that?
How can I not have the dots of the distribution at the bottom, or at
least, make them occupy less vertical space?
Albert Vilella wrote:> Hi, > > I have a densityplot like this: > > x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)) > f = sample(c("A","B","C","D","E"),300,replace=TRUE) > df=data.frame(x,f) > library(lattice) > attach(df) > densityplot(~x, groups=f) > > And I want to add a legend with the colours for the factors. How can I do that? > How can I not have the dots of the distribution at the bottom, or at > least, make them occupy less vertical space?Change the last line to the following: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE) See ?panel.densityplot .> ______________________________________________ > R-help at stat.math.ethz.ch 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. >-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
Are this legend colors correlated to the plot? If I do a: densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE,col=heat.colors(5)) I get different colors in the legend than the plot... On 11/29/06, Chuck Cleland <ccleland at optonline.net> wrote:> Albert Vilella wrote: > > Hi, > > > > I have a densityplot like this: > > > > x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)) > > f = sample(c("A","B","C","D","E"),300,replace=TRUE) > > df=data.frame(x,f) > > library(lattice) > > attach(df) > > densityplot(~x, groups=f) > > > > And I want to add a legend with the colours for the factors. How can I do that? > > How can I not have the dots of the distribution at the bottom, or at > > least, make them occupy less vertical space? > > Change the last line to the following: > > densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE) > > See ?panel.densityplot . > > > ______________________________________________ > > R-help at stat.math.ethz.ch 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. > > > > -- > Chuck Cleland, Ph.D. > NDRI, Inc. > 71 West 23rd Street, 8th floor > New York, NY 10010 > tel: (212) 845-4495 (Tu, Th) > tel: (732) 512-0171 (M, W, F) > fax: (917) 438-0894 >
Try specifying it at the par.settings= level since that is where both
the plot and the legend get it from:
set.seed(1)
DF <- data.frame(x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6)),
f =
sample(c("A","B","C","D","E"),300,replace=TRUE))
library(lattice)
densityplot(~ x, DF, groups = f, auto.key = TRUE, plot.points = FALSE,
par.settings = list(superpose.line = list(col = heat.colors(5))))
On 11/29/06, Albert Vilella <avilella at gmail.com>
wrote:> Are this legend colors correlated to the plot?
>
> If I do a:
>
> densityplot(~x, groups=f, plot.points=FALSE,
auto.key=TRUE,col=heat.colors(5))
>
> I get different colors in the legend than the plot...
>
>
> On 11/29/06, Chuck Cleland <ccleland at optonline.net> wrote:
> > Albert Vilella wrote:
> > > Hi,
> > >
> > > I have a densityplot like this:
> > >
> > > x = c(rnorm(100,1,2),rnorm(100,2,4),rnorm(100,3,6))
> > > f =
sample(c("A","B","C","D","E"),300,replace=TRUE)
> > > df=data.frame(x,f)
> > > library(lattice)
> > > attach(df)
> > > densityplot(~x, groups=f)
> > >
> > > And I want to add a legend with the colours for the factors. How
can I do that?
> > > How can I not have the dots of the distribution at the bottom, or
at
> > > least, make them occupy less vertical space?
> >
> > Change the last line to the following:
> >
> > densityplot(~x, groups=f, plot.points=FALSE, auto.key=TRUE)
> >
> > See ?panel.densityplot .
> >
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch 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.
> > >
> >
> > --
> > Chuck Cleland, Ph.D.
> > NDRI, Inc.
> > 71 West 23rd Street, 8th floor
> > New York, NY 10010
> > tel: (212) 845-4495 (Tu, Th)
> > tel: (732) 512-0171 (M, W, F)
> > fax: (917) 438-0894
> >
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>