如何修改此代码以显示哪种颜色指的是哪个变量。
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)
答案 0 :(得分:1)
据我所知,你只想添加一个传奇。
假设您xyplot
是lattice
包中的那个,您可以执行以下操作:
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"))))