R + xyplot + key with multiple references -


i have plot similar this:

w=rnorm(9) z=rnorm(9) a=as.factor(c(rep(c("a1","a2","a3"),3))) b=as.factor(c(rep("b1",3),rep("b2",3),rep("b3",3))) c=as.factor(c("c1","c1","c2","c2","c3","c3","c1","c2","c3"))  xyplot(w~z,type="p",cex=1.4,        panel=function(x, y, ...) {          panel.xyplot(x=z[1], y=w[1],pch=15,col="red",...);          panel.xyplot(x=z[2], y=w[2],pch=15,col="green",...);          panel.xyplot(x=z[3], y=w[3],pch=15,col="blue",...);          panel.xyplot(x=z[4], y=w[4],pch=16,col="red",...);          panel.xyplot(x=z[5], y=w[5],pch=16,col="green",...);          panel.xyplot(x=z[6], y=w[6],pch=16,col="blue",...);          panel.xyplot(x=z[7], y=w[7],pch=17,col="red",...);          panel.xyplot(x=z[8], y=w[8],pch=17,col="green",...);          panel.xyplot(x=z[9], y=w[9],pch=17,col="blue",...);          ltext(x=x, y=y+0.1, labels=c) }) 

and have been trying lot without success key this:

enter image description here

i tried key function, legend function, trying create more 1 key in same graph… i’m lost!!

i know doing in lattice, ggplot makes kind of thing pretty easy.

my.data<-data.frame(w,z,a,b,c) ggplot(my.data,aes(x=w,y=z,colour=a,shape=b,label=c)) +    geom_point(size=3) +    geom_text(hjust=-0.2,vjust=-0.2) 

enter image description here

i had hard time figuring out how guide labels. realized if have labels, why need guide?


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -