[英]Legend with color filling and shading lines in Base R
In my plot I have two intersecting polygons, one colored and one with shading lines. 在我的情节中,我有两个相交的多边形,一个是彩色的,一个是阴影线。 In the legend I would like the two polygons and the intersection array represented correctly.
在图例中,我希望正确表示两个多边形和交叉点数组。 Here is what I have:
这是我有的:
plot(1:4, 1:4, type="n", xaxt="n", xlab="", yaxt="n", ylab="")
polygon(c(2,4,2), c(1,3,3), col="gray")
polygon(c(3,3,1), c(1,3,2), col="red", density=10)
legend("topleft", legend=c("A", "B", "AB"), fill=c("gray", "red", "gray"),
density=c(NA, 10, NA), bty="n")
Is it possible to change the border color in the legend for B to red and add red shading lines to the symbol for AB? 是否可以将B图例中的边框颜色更改为红色,并将红色阴影线添加到AB的符号中?
You should add argument border=
to legend()
to change the border color of small boxes and then add another call to legend()
to overlay shading to AB box with your color. 您应该将参数
border=
添加到legend()
以更改小方框的边框颜色,然后再添加一个对legend()
调用,以使用您的颜色将阴影重叠到AB框。 In the second legend()
line I set density=
for the AB to 10 and changed also fill=
to red for the same box. 在第二个
legend()
行中,我将AB的density=
设置为10,并将同一框中的fill=
更改为红色。
plot(1:4, 1:4, type="n", xaxt="n", xlab="", yaxt="n", ylab="")
polygon(c(2,4,2), c(1,3,3), col="gray")
polygon(c(3,3,1), c(1,3,2), col="red", density=10)
legend("topleft", legend=c("A", "B", "AB"), fill=c("gray", "red", "gray"),
density=c(NA, 10, NA), bty="n",border=c("black", "red", "black"))
legend("topleft", legend=c("A", "B", "AB"), fill=c("gray", "red", "red"),
density=c(NA, 10, 10), bty="n",border=c("black", "red", "black"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.