如何在 r 中获取 coplot 的图例?

How can I get legend for coplot in r?

使用 iris 数据集,当我将点的颜色定义为 variable 变量时,我将找到一种方法来获取 coplot 中的图例,在此示例中 ( Species)。 换句话说,我想看一个 传说 来告诉我 哪个形状和颜色代表哪个物种 ?

脚本如下

coplot(Sepal.Width~Sepal.Length|Petal.Width*Petal.Length, data = iris,
number=c(3,3),overlap=.5,col=as.numeric(iris$Species),
pch=as.numeric(iris$Species)+1)

这是生成的图表:

coplot(Sepal.Width~Sepal.Length|Petal.Width*Petal.Length, data = iris,
       number=c(3,3),overlap=.5,col=as.numeric(iris$Species),
       pch=as.numeric(iris$Species)+1)

legend("topright", pch = unique(as.numeric(iris$Species)+1), 
       col = unique(as.numeric(iris$Species)), 
       legend = unique(iris$Species))

您只需将图例位置调整到更适合您的身材大小即可。