Overlay Scatter Plots(修改编程代码)

时间:2016-01-28 13:11:19

标签: r

如何修改此代码以显示哪种颜色指的是哪个变量。

 a1= rnorm(10)
    a2= rnorm(10)
    a3= rnorm(10)
    d=rnorm(10)
    df<-data.frame(a1,a2,a3,d)
    xyplot(d ~ a1 + a2 + a3, data=df,pch = 21, fill = c("black", "red", "green"), cex = 1) 

1 个答案:

答案 0 :(得分:1)

据我所知,你只想添加一个传奇。 假设您xyplotlattice包中的那个,您可以执行以下操作:

library(lattice)
a1= rnorm(10)
a2= rnorm(10)
a3= rnorm(10)
d=rnorm(10)
df<-data.frame(a1,a2,a3,d)
xyplot(d ~ a1 + a2 + a3, data=df,pch = 21, 
    fill = c("black", "red", "green"), cex = 1, 
    key=list(corner=c(0,1),points=list(col=c("black", "red", "green"),lwd=3),
    text=list(c("a1","a2","a3"))))