簡體   English   中英

在 R 圖的圖例中疊加兩個圓圈

[英]Overlay two circles in a legend of an R plot

在 R 中,我可以像...一樣編寫圖例項嗎?

在此處輸入圖片說明

我將數據繪制為紅點,由紅色或橙色外圈覆蓋,其中這些外圈的大小代表一個屬性,外圈的顏色代表一個屬性。 我怎么能在傳說中重復呢?

在此處輸入圖片說明

到目前為止,我只有傳說......

legend("topleft",
  legend = c("elevation of centerline", "gradient", "boulders", "boulders in steps", "boulders not in steps"),    
  lty=c(1,1,0,0,0), pch=c(NA, NA, 19, 19,19), col=c("black", "gray", "red", "orange", "green"),
  pt.cex=c(0.8, 0.8, 0.8, 2, 2)
)

我試圖給第三個元素一個向量,例如

 pch=c(NA, NA, c(19, 19), c(19,19))

沒有運氣。

如果你正在嘗試創建“項目A”和“B項”的符號,你應該使用的變化pt.bgpt.lwd除了其他legend你目前正在使用的參數(如ltypchcol ,和pt.cex )。 使用下面的示例並調整代碼以查看這些參數如何相互交互:

x=seq(1,10,1)
y<-seq(5,50,5)
z<-rep(c(1:2),5)
df<-data.frame(x,y,z)
df$z<-factor(df$z)

plot(y~x,data=df,type="l",lty=1,lwd=1,col="grey60")
points(y~x,data=df[df$z==1,],pch=16,col="orange",cex=df$x[df$z==1])
points(y~x,data=df[df$z==1,],pch=16,col="red",cex=1)
points(y~x,data=df[df$z==2,],pch=16,col="green",cex=df$x[df$z==2])
points(y~x,data=df[df$z==2,],pch=16,col="red",cex=1)

legend("topleft",legend=c("Item A","Item B"),pch=c(21,21),col=c("green","orange"),
       pt.bg=c("red","red"),pt.lwd=c(6,6),lty=c(0,0),pt.cex=c(2,2),cex=1)

在此處輸入圖片說明

我知道這個問題很舊,但作為參考,我認為再次調用圖例來覆蓋紅點會更容易。

legend("topleft",
  legend = c("elevation of centerline", "gradient", "boulders in steps", "boulders not in steps"),    
  lty=c(1,1,0,0), pch=c(NA, NA, 19,19), col=c("black", "gray", "orange", "green"),
  pt.cex=c(0.8, 0.8, 2, 2)
)


legend("topleft",
  legend = c("elevation of centerline", "gradient", "boulders in steps", "boulders not in steps"),   
  lty=c(1,1,0,0), pch=c(NA, NA, 19,19), col=c(NA, NA, "red", "red" ),
  pt.cex=c(0.8,0.8,0.8,0.8)
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM