[R] positioning of color key in levelplot
Deepayan Sarkar
deepayan.sarkar at gmail.com
Sun May 11 22:20:03 CEST 2008
On 5/11/08, E C <mmmraspberries at hotmail.com> wrote:
> Is there a way of positioning the color key in levelplot when the axes are on a categorical (rather than numerical) scale? I've put some sample code below. I need to add a secondary y axis to the right side of my plot but then the labels interfere with the color key (which is currently on the right side). Is there a way to shift the color key over a bit more to the right? I've tried playing around with the arguments "x", "y", and "corner"in the colorkey list, but it doesn't seem to change anything. I've also tried putting the colorkey on the left side instead, but then the secondary y axis labels are cut-off. Thanks for any help!
>
> group1 <- c(rep("A1", 40), rep("A2", 40))
> group2 <-rep(c(rep("C1", 5), rep("C2", 5), rep("C3", 5), rep("C4", 5), rep("C5", 5), rep("C6", 5), rep("C7", 5), rep("C8", 5)),2)
> num <- rnorm(80)
> group3 <- rep(seq(0,4,1),16)
> data <- data.frame(group1, group2, num, group3)
It has more to do with adding space for the axis, rather than anything
to do with the legend directly.
levelplot(num ~ as.factor(group3) * group2|group1,
data=data,
col.regions=rev(heat.colors(25)),
colorkey=list(space="right"),
par.settings = list(layout.widths = list(axis.key.padding = 5)),
region=T, layout=c(1,2),
scales=list(y=list(alternating=c(1,1,1))))
trellis.focus("panel", 1, 2, clip.off=T, highlight = FALSE)
panel.axis(at=seq(1,8,1), labels=c(rep("Blah",8)), side=c("right"), outside=T)
trellis.focus("panel", 1, 1, clip.off=T, highlight = FALSE)
panel.axis(at=seq(1,8,1), labels=c(rep("Blah",8)), side=c("right"), outside=T)
trellis.unfocus()
-Deepayan
More information about the R-help
mailing list