在散点图旁边显示颜色编码的图例

时间:2017-09-24 13:36:04

标签: r

查看此代码:

pairs(Iris[1:3], main = "Anderson's Iris Data -- 3 species",
pch = c(21),  cex = 2,bg = c("red","green3","blue")[unclass(iris$Species)])

是否可以将组/类物种显示为图例颜色编码?

1 个答案:

答案 0 :(得分:3)

pairs(iris[1:3], main = "Anderson's Iris Data -- 3 species",
      pch = c(21),  cex = 2, bg = c("red","green3","blue")[unclass(iris$Species)], oma=c(4,4,6,10))
par(xpd=TRUE)
legend(0.55, 1, as.vector(unique(iris$Species)),  fill=c("red", "green3", "blue"))

来自?对: 图形参数可以作为绘图的参数给出,例如main。除非另有说明,否则将适当设置par(“oma”)。因此,任何在对之前指定par的尝试都将导致覆盖。

此外,在pairs中控制图例位置非常复杂。

enter image description here

我建议使用库(GGally)

library(GGally)
ggpairs(iris, aes(color = Species), columns = 1:4)

enter image description here