0

我正在尝试在 R 中绘制一个图例,我

dfk <- subset(df, df$V2 != -1 & df$V5>-50 & df$V5< 0 &  df$V6>-50 & df$V6<0)
plot(dfk$V5,dfk$V6, main = "1880 - 1 - 1/4", sub = NULL, xlab = "LON", 
     ylab = "LAT", ylim=c(-50,0),xlim=c(-50,0), 
     col = rainbow(length(dfk$V2))[rank(dfk$V2)], 
     pch=c(1:25)[rank(dfk$V2)],cex=2)
legend('topright',legend=dfk$V2[!duplicated(dfk$V2)],
       col=rainbow(length(dfk$V2))[ rank(dfk$V2)[!duplicated(dfk$V2)] ],
       pch=c(1:25)[rank(dfk$V2)[!duplicated(dfk$V2)]],
       cex=2)

这里是数据

V2  V3 V4  V5    V6
16  1  2 -29.5 -10.5    
16  1  6 -30.5 -11.5 
16  1 10 -30.5 -11.5 
16  1 14 -30.5 -11.5 
16  1 22 -32.5 -13.5 
119  1 22 -30.5 -12.5 
16  2  2 -32.5 -13.5 
119  2  2 -31.5 -14.5 
16  2  6 -33.5 -14.5 
119  2  6 -31.5 -14.5 
16  2 10 -33.5 -14.5
119  2 10 -31.5 -14.5 
16  2 14 -33.5 -14.5 
119  2 14 -31.5 -14.5 
119  3  2 -32.5 -15.5 
119  3  6 -33.5 -17.5 
325  3 10 -32.5 -16.5 
327  3 10 -31.5 -17.5
325  3 14 -32.5 -17.5 
327  3 14 -31.5 -18.5 
327  3 18 -31.5 -18.5 
325  3 22 -32.5 -17.5 
327  3 22 -31.5 -18.5 
325  4  2 -32.5 -17.5 
327  4  2 -31.5 -19.5 
325  4  6 -32.5 -18.5 
327  4  6 -31.5 -19.5 
325  4 10 -32.5 -18.5 
325  4 14 -32.5 -19.5 
327  4 14 -31.5 -20.5 
327  4 18 -31.5 -20.5

问题是它打印出三个类别(16-119-325-327)的图例,但它不打印327类别的数据!

谢谢

4

1 回答 1

2

有 25 个可用pch符号可供选择,最高等级V2是 27.5,因此没有匹配符号。您可以尝试将排名除以 2,您将匹配到一个pch符号

plot(dfk$V5,dfk$V6, main = "1880 - 1 - 1/4", sub = NULL, xlab = "LON", ylab = "LAT",
         ylim=c(-50,0),xlim=c(-50,0), col = rainbow(length(dfk$V2))               
         [rank(dfk$V2)],pch=c(1:25)[rank(dfk$V2)/2],cex=2)

legend('topright',legend=dfk$V2[!duplicated(dfk$V2)],col=rainbow(length(dfk$V2))
         [rank(dfk$V2)[!duplicated(dfk$V2)]],pch=c(1:25)
         [rank(dfk$V2)[!duplicated(dfk$V2)]/2],cex=2)
于 2013-09-03T16:27:18.660 回答