 user3810226 - 3 years ago 93
R Question

# Lattice auto key lty not working

Hello below is a plot created using lattice. I am using lty=c(1, 2) so the lines are black but of two types. In the key however, the lines are colored as blue & pink? I am not sure how to correct this. Thanks!

``````column1 <- c(89.66, 89.66, 93.10, 96.55, 86.21, 89.66, 86.21, 79.31, 79.31, 79.31, 89.66, 82.76, 100, 93.33, 90, 93.33, 96.67, 96.67, 93.33, 93.33, 90, 93.33, 93.33, 93.33)
column2 <- rep(c("SF36", "SF12"), c(12, 12))
column3 <- rep(c("1/12", "2/12", "3/12", "4/12", "5/12", "6/12", "7/12", "8/12", "9/12", "10/12", "11/12", "12/12"), 2)
column3 <- factor(column3, levels=c("1/12", "2/12", "3/12", "4/12", "5/12", "6/12", "7/12", "8/12", "9/12", "10/12", "11/12", "12/12"))
data2 <- data.frame(column1, column2, column3)
xyplot(column1~column3, data=data2, groups=column2, lwd=2, col=c("black", "black"), lty=c(1, 2), pch=2, type="o", ylab=list(label="% of People who Answered", cex=2), scales=list(x=list(cex=2, rot=90), y=list(cex=2)), xlab=list(label="Proportion of Survey Progressed Through", cex=2), auto.key=list(space="top", columns=2, title="Group", cex.title=2, lines=TRUE, points=FALSE, cex=2))
`````` Weihuang Wong

Try setting the plot parameters via the `par.settings` argument:

``````xyplot(column1~column3, data=data2, groups=column2,
par.settings = list(superpose.line = list(col = "black",
lty = c(1, 2),
lwd = 2),
superpose.symbol = list(pch = 2, col = "black")),
type="o",
ylab=list(label="% of People who Answered", cex=2),
scales=list(x=list(cex=2, rot=90), y=list(cex=2)),
xlab=list(label="Proportion of Survey Progressed Through", cex=2),
auto.key=list(space="top", columns=2, title="Group", cex.title=2,
lines=TRUE, points=FALSE, cex=2))
``````
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download