符号在情节传奇中的白色背景(pt.bg没有效果)

时间:2017-08-18 11:39:00

标签: r legend

我正在尝试为一个情节添加一个图例,但我无法让pch符号填充白色。 pt.bg似乎没有效果:

plot(1, 1)
legend(
    x = "topright",
    legend = c("alle Messzeitpunkte", "ohne selbstinitiierte", "erwartete"),
    lty = c("solid", "dashed", "dotted"),
    pch = c(16, 1, NA),
    pt.bg = c("black", "white", NA)
)

enter image description here

1 个答案:

答案 0 :(得分:1)

pch = 1是一个空心圆,无法填充。 pch = 16是一个没有边框的填充形状。 pch = 1pch = 16的颜色由col定义。只有pch = 21可以填充与其边框颜色不同的颜色。 pch = 21的填充颜色由许多绘图函数中的bgpt.bg中的legend()定义。

plot(1:10, rep(1, 10), ylim = c(0, 2), axes = FALSE)
legend(
    x = 1, y = 2,
    legend = c("a", "b", "c", "d", "e"),
    lty = "solid",
    pch = c(1, 1, 1),
    col = c("black", "black", "red", "red", "red"),
    pt.bg = c("black", "white", "red", "green", "blue")
)
legend(
    x = 2.5, y = 2,
    legend = c("a", "b", "c", "d", "e"),
    lty = "solid",
    pch = c(16, 16, 16),
    col = c("black", "black", "red", "red", "red"),
    pt.bg = c("black", "white", "red", "green", "blue")
)
legend(
    x = 4, y = 2,
    legend = c("a", "b", "c", "d", "e"),
    lty = "solid",
    pch = c(21, 21, 21),
    col = c("black", "black", "red", "red", "red"),
    pt.bg = c("black", "white", "red", "green", "blue")
)

enter image description here