Reputation: 49
I created a pentagram. The code is
p <- cbind(x = c(0, 1, 2,-0.5 , 2.5 ,0), y = c(0, 1, 0,0.6, 0.6,0))
plot(p)
lines(p)
But how can I fill in color like this. I tried to use polygon function but couldn't figure out how to describe the borderline.
Upvotes: 2
Views: 503
Reputation: 24262
A solution based on the ggplot2
package:
df <- data.frame(x = c(0, 1, 2,-0.5 , 2.5 ,0), y = c(0, 1, 0,0.6, 0.6,0))
library(ggplot2)
ggplot(data=df, aes(x, y)) +
geom_polygon(fill="blue") +
theme_bw()
Upvotes: 1
Reputation: 72899
polygon
works with fillOddEven=TRUE
.
plot(p)
lines(p)
polygon(p, col="darkblue", fillOddEven=TRUE)
Data:
p <- structure(c(0, 1, 2, -0.5, 2.5, 0, 0, 1, 0, 0.6, 0.6, 0), .Dim = c(6L,
2L), .Dimnames = list(NULL, c("x", "y")))
Upvotes: 3