简体   繁体   English

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

[英]show color coded legend beside scatter plot

Looking at this code: 看看这段代码:

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

is it possible to show the groups/classes Species as legend color coded? 是否可以将组/类物种显示为图例的颜色编码?

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

From ?pairs: Graphical parameters can be given as arguments to plot such as main. 来自?对:图形参数可以作为绘图的参数给出,例如main。 par("oma") will be set appropriately unless specified. 除非另有说明,否则将适当设置par(“oma”)。 Hence any attempts to specify par before pairs will result in override. 因此,任何在对之前指定par的尝试都将导致覆盖。

Additionally it is very complicated to control the legend position in pairs . 另外, pairs控制图例位置非常复杂。

在此输入图像描述

I recommend using library(GGally) 我推荐使用库(GGally)

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

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM