我的情节类似于:
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)
})
现在,我一直在努力尝试获得这样一个关键字:
我尝试使用键功能,使用图例功能,尝试在同一个图形中创建多个键...我迷路了!!
答案 0 :(得分:1)
我知道你在lattice
中这样做了,但是ggplot
让这件事变得非常简单。
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)
我很难弄清楚如何获得标签指南。但后来我意识到,如果你有标签,为什么还需要指南?