格子键与绘图上的美学不对应

时间:2016-10-21 15:36:30

标签: r graphics lattice

以下是使用晶格创建的图。我使用的是lty = c(1,2),所以线条是黑色但有两种类型。然而,在键中,线条被着色为蓝色和蓝色。粉?我不知道如何纠正这个问题。谢谢!

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))

1 个答案:

答案 0 :(得分:2)

尝试通过par.settings参数设置绘图参数:

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))

输出: enter image description here