Reputation: 8366
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.
Upvotes: 2
Views: 1929
Reputation: 94277
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
.
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.
Upvotes: 5