【问题标题】:show color coded legend beside scatter plot在散点图旁边显示颜色编码的图例
【发布时间】:2017-09-24 13:36:03
【问题描述】:

看这段代码:

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

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

【问题讨论】:

标签: r


【解决方案1】:
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"))

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

另外控制pairs中的图例位置非常复杂。

我推荐使用库(GGally)

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

【讨论】:

    猜你喜欢
    • 2020-02-15
    • 2018-06-23
    • 1970-01-01
    • 2020-05-29
    • 1970-01-01
    • 2017-05-24
    • 1970-01-01
    • 2021-05-25
    • 2021-10-29
    相关资源
    最近更新 更多