Skip to content

Instantly share code, notes, and snippets.

@bjurban
Last active August 29, 2015 14:22
Show Gist options
  • Save bjurban/9531d1a5fedfc54d3696 to your computer and use it in GitHub Desktop.
Save bjurban/9531d1a5fedfc54d3696 to your computer and use it in GitHub Desktop.
lattice legends with groups
# Legends and Groups in Lattice
# Bryan Urban
# 2015-06-01
library(lattice)
head(mtcars)
my.col <- c("black", "blue", "red")
my.settings <-
list(superpose.line = list(col=my.col),
superpose.polygon = list(col=my.col),
superpose.symbol = list(col=my.col))
g.lab <- as.character(unique(mtcars$cyl))
g.lab <- paste(g.lab, "cyl")
xyplot(mpg~hp, groups=cyl, mtcars, type='p',
ylab = "mpg",
xlab = "hp",
key=list(text=list(g.lab, cex=4),# font="Helvetica"),
lines=list(col=my.col, width=4),
points=list(pch=4, col=my.col),
rect=list(col=my.col, border=F, height=0.5, size=8),
corner=c(.9, .9),
# space="top",
# space="right",
padding=3,
columns=2,
border="black",
background="white"),
par.settings = my.settings
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment