我制作了一个箱形图并添加了平均值作为一个点。在图例中,我想把填充的方块对应于方框。嵌套到我想要添加与平均值对应的符号的框。但是,我的尝试没有成功。有什么帮助吗?
A <- 1:10
B <- 2:11
DF <- data.frame(A, B)
boxplot(DF, col = gray.colors(2), ylim = c(0,20))
points(1, mean(A), pch = 3, col = "red")
points(2, mean(B), pch = 3, col = "red")
legend("topleft", fill = c(gray.colors(2), 0), legend = c("A", "B", "Mean"), horiz = T,
pch = 3, col = "red")
答案 0 :(得分:1)
这可以通过包含前面框中的默认值或NA
值进行排序。 pch=
个参数,反之亦然。像这样:
legend("topleft", fill = c(gray.colors(2), 0), border=c("black","black",NA),
legend = c("A", "B", "mean"), horiz = TRUE, pch = c(NA,NA,3), col=c(NA,NA,"red"))