Hi,
I'm creating some lattice plots that have a key and I'd like to put a
label on the key. The problem is that the text label for the key
prevents the values of the group variables from being shown (see example
below). I don't think that this is a feature, but I might be abusing the
title arg for key.
I'm using R Version 2.3.0 (2006-04-24) on Windows XP and lattice V0.13-8
Thanks,
Max
library(lattice)
testData <- expand.grid(
A = letters[1:2],
B = letters[3:4],
C = letters[5:6])
testData$y <- rnorm(dim(testData)[1])
stripplot(
y ~ A|B, data = testData,
groups = C,
panel = function(x, y, groups, subscripts)
{
group.values <- sort(unique(groups))
for (i in seq(along=group.values))
{
id <- (groups[subscripts] == group.values[i])
current.val <- group.values[i]
panel.stripplot(x[id], y[id],
jitter.data = FALSE, horizontal = FALSE,
col = trellis.par.get()$superpose.symbol$col[i],
pch = trellis.par.get()$superpose.symbol$pch[i])
panel.linejoin(
x[id], y[id], horizontal=F,
col = trellis.par.get()$superpose.symbol$col[i],
lty = trellis.par.get()$superpose.line$lty[i],
lwd = trellis.par.get()$superpose.line$lwd[i])
}
},
main = "Some Text",
key = list(
columns = 2,
text=list(
# comment the next line out to see
# the values of the grouping variable
title = "More Text",
lab = letters[5:6]),
lines=list(
col = trellis.par.get()$superpose.symbol$col[1:2],
lwd = trellis.par.get()$superpose.line$lwd[1:2],
lty = trellis.par.get()$superpose.line$lty[1:2]),
points = list(
col = trellis.par.get()$superpose.symbol$col[1:2],
pch = trellis.par.get()$superpose.symbol$pch[1:2])))
----------------------------------------------------------------------
LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}}
Kuhn, Max wrote:> Hi, > > I'm creating some lattice plots that have a key and I'd like to put a > label on the key. The problem is that the text label for the key > prevents the values of the group variables from being shown (see example > below). I don't think that this is a feature, but I might be abusing the > title arg for key. > > I'm using R Version 2.3.0 (2006-04-24) on Windows XP and lattice V0.13-8 > > Thanks, > > Max > > > library(lattice) > testData <- expand.grid( > A = letters[1:2], > B = letters[3:4], > C = letters[5:6]) > testData$y <- rnorm(dim(testData)[1]) > > stripplot( > y ~ A|B, data = testData, > groups = C, > panel = function(x, y, groups, subscripts) > { > group.values <- sort(unique(groups)) > for (i in seq(along=group.values)) > { > id <- (groups[subscripts] == group.values[i]) > current.val <- group.values[i] > panel.stripplot(x[id], y[id], > jitter.data = FALSE, horizontal = FALSE, > col = trellis.par.get()$superpose.symbol$col[i], > pch = trellis.par.get()$superpose.symbol$pch[i]) > panel.linejoin( > x[id], y[id], horizontal=F, > col = trellis.par.get()$superpose.symbol$col[i], > lty = trellis.par.get()$superpose.line$lty[i], > lwd = trellis.par.get()$superpose.line$lwd[i]) > } > }, > main = "Some Text", > key = list( > columns = 2, > text=list( > # comment the next line out to see > # the values of the grouping variable > title = "More Text", > lab = letters[5:6]), > lines=list( > col = trellis.par.get()$superpose.symbol$col[1:2], > lwd = trellis.par.get()$superpose.line$lwd[1:2], > lty = trellis.par.get()$superpose.line$lty[1:2]), > points = list( > col = trellis.par.get()$superpose.symbol$col[1:2], > pch = trellis.par.get()$superpose.symbol$pch[1:2]))) > > ---------------------------------------------------------------------- > LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}} >Hi, Max, I think you missed this in ?xyplot under the "key" arguement: The '"text"' component has to have a character or expression vector as its first component, and the length of this vector determines the number of rows. I don't see any documentation on "text" allowing a "title" element. If you want to do what I think you want, try this key instead: key = list( columns = 2, text=list( c(paste("More Text", letters[5], sep = " "), letters[6])), lines=list( col = trellis.par.get()$superpose.symbol$col[1:2], lwd = trellis.par.get()$superpose.line$lwd[1:2], lty = trellis.par.get()$superpose.line$lty[1:2]), points = list( col = trellis.par.get()$superpose.symbol$col[1:2], pch = trellis.par.get()$superpose.symbol$pch[1:2])) It's not pretty, but you get idea. Perhaps others might have better solutions. --sundar
Hi Max, You have 'title' as a component of the 'text' component of key. According to the help page for xyplot, 'title' is a component of key. AFAICS, 'text' does not have a 'title' component. Peter Ehlers Kuhn, Max wrote:> Hi, > > I'm creating some lattice plots that have a key and I'd like to put a > label on the key. The problem is that the text label for the key > prevents the values of the group variables from being shown (see example > below). I don't think that this is a feature, but I might be abusing the > title arg for key. > > I'm using R Version 2.3.0 (2006-04-24) on Windows XP and lattice V0.13-8 > > Thanks, > > Max > > > library(lattice) > testData <- expand.grid( > A = letters[1:2], > B = letters[3:4], > C = letters[5:6]) > testData$y <- rnorm(dim(testData)[1]) > > stripplot( > y ~ A|B, data = testData, > groups = C, > panel = function(x, y, groups, subscripts) > { > group.values <- sort(unique(groups)) > for (i in seq(along=group.values)) > { > id <- (groups[subscripts] == group.values[i]) > current.val <- group.values[i] > panel.stripplot(x[id], y[id], > jitter.data = FALSE, horizontal = FALSE, > col = trellis.par.get()$superpose.symbol$col[i], > pch = trellis.par.get()$superpose.symbol$pch[i]) > panel.linejoin( > x[id], y[id], horizontal=F, > col = trellis.par.get()$superpose.symbol$col[i], > lty = trellis.par.get()$superpose.line$lty[i], > lwd = trellis.par.get()$superpose.line$lwd[i]) > } > }, > main = "Some Text", > key = list( > columns = 2, > text=list( > # comment the next line out to see > # the values of the grouping variable > title = "More Text", > lab = letters[5:6]), > lines=list( > col = trellis.par.get()$superpose.symbol$col[1:2], > lwd = trellis.par.get()$superpose.line$lwd[1:2], > lty = trellis.par.get()$superpose.line$lty[1:2]), > points = list( > col = trellis.par.get()$superpose.symbol$col[1:2], > pch = trellis.par.get()$superpose.symbol$pch[1:2]))) > > ---------------------------------------------------------------------- > LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}} > > ______________________________________________ > 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
Peter and Sundar,
Thanks, I did miss that. I used:
key = list(
title = "More Text",
cex.title = 1,
columns = 2,
text=list(
to get what I wanted.
Max
-----Original Message-----
From: P Ehlers [mailto:ehlers at math.ucalgary.ca]
Sent: Thursday, June 01, 2006 4:14 PM
To: Kuhn, Max
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Key titles in Lattice
Hi Max,
You have 'title' as a component of the 'text' component of key.
According to the help page for xyplot, 'title' is a component
of key. AFAICS, 'text' does not have a 'title' component.
Peter Ehlers
Kuhn, Max wrote:> Hi,
>
> I'm creating some lattice plots that have a key and I'd like to put
a
> label on the key. The problem is that the text label for the key
> prevents the values of the group variables from being shown (see
example> below). I don't think that this is a feature, but I might be abusing
the> title arg for key.
>
> I'm using R Version 2.3.0 (2006-04-24) on Windows XP and lattice
V0.13-8>
> Thanks,
>
> Max
>
>
> library(lattice)
> testData <- expand.grid(
> A = letters[1:2],
> B = letters[3:4],
> C = letters[5:6])
> testData$y <- rnorm(dim(testData)[1])
>
> stripplot(
> y ~ A|B, data = testData,
> groups = C,
> panel = function(x, y, groups, subscripts)
> {
> group.values <- sort(unique(groups))
> for (i in seq(along=group.values))
> {
> id <- (groups[subscripts] == group.values[i])
> current.val <- group.values[i]
> panel.stripplot(x[id], y[id],
> jitter.data = FALSE, horizontal = FALSE,
> col = trellis.par.get()$superpose.symbol$col[i],
> pch = trellis.par.get()$superpose.symbol$pch[i])
> panel.linejoin(
> x[id], y[id], horizontal=F,
> col = trellis.par.get()$superpose.symbol$col[i],
> lty = trellis.par.get()$superpose.line$lty[i],
> lwd = trellis.par.get()$superpose.line$lwd[i])
> }
> },
> main = "Some Text",
> key = list(
> columns = 2,
> text=list(
> # comment the next line out to see
> # the values of the grouping variable
> title = "More Text",
> lab = letters[5:6]),
> lines=list(
> col = trellis.par.get()$superpose.symbol$col[1:2],
> lwd = trellis.par.get()$superpose.line$lwd[1:2],
> lty = trellis.par.get()$superpose.line$lty[1:2]),
> points = list(
> col = trellis.par.get()$superpose.symbol$col[1:2],
> pch = trellis.par.get()$superpose.symbol$pch[1:2])))
>
> ----------------------------------------------------------------------
> LEGAL NOTICE\ Unless expressly stated otherwise, this
messag...{{dropped}}>
> ______________________________________________
> 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
----------------------------------------------------------------------
LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}}