简体   繁体   English

设置多边形的背景色

[英]Setting the background colour of a polygon

Is there a way to set the background colour of a polygon? 有没有办法设置多边形的背景颜色? I want to get a plot like this... 我想得到这样的情节...

set.seed(1)
n <- 100
xx <- c(0:n, n:0)
yy <- c(c(0,cumsum(stats::rnorm(n))), rev(c(0,cumsum(stats::rnorm(n)))))

plot   (xx, yy, type="n", xlab="Time", ylab="Distance")
polygon(xx, yy, angle=45, density=10)
polygon(xx, yy+5, col="white")
polygon(xx, yy+5, angle=45, density=10, col="red")

But ideally without the penultimate line to set the background (I am plotting multiple polygons within a function I am writing). 但是理想情况下,没有倒数第二行来设置背景(我正在编写的函数内绘制多个多边形)。 Is there an argument I can use in the final line that will negate the whole of the penultimate line? 我可以在最后一行使用否定第二个倒数第二行的论点吗? Cheers. 干杯。

丑陋

My answer is 'no' - help(polygon) gives you col for filling the polygon but also uses it for the line shading colour if using angle and density . 我的回答是“否” help(polygon)为您提供用于填充多边形的col ,但如果使用angledensity也可以将其用于线条阴影颜色。

This is a relic of the old days when your pen plotter could only pick up one pen at at time... 这是过去您的笔式绘图仪一次只能捡起一支笔的遗物...

Doing it twice shouldn't be a problem. 这样做两次不是问题。 Write your own function that takes a polygon and two colour parameters and calls polygon twice. 自己写的函数,采用多边形和两个颜色参数,并呼吁polygon的两倍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM