shoorideh
shoorideh

Reputation: 173

Overlay Scatter Plots (Modifying the programming code)

How can I modify this code to show which color refers to which variable.

 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) 

Upvotes: 0

Views: 25

Answers (1)

Vongo
Vongo

Reputation: 1434

From what I understand, you just want to add a legend. Assuming that you xyplot is the one from lattice package, you could do something like :

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

Upvotes: 1

Related Questions