如何在r中获得coplot的传奇?

时间:2017-01-18 18:08:08

标签: r plot data-visualization lattice

使用iris数据集,当我将点的颜色定义为coplot变量时,我将找到一种方法在variable中获取图例(在此示例中为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)

这是生成的图表: enter image description here

1 个答案:

答案 0 :(得分:2)

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

您只需将图例位置调整为更适合您的图形尺寸。