I refer to the answer for this question and have additional question.
I have modify the code as below:
library(ggplot2)
ids <- letters[1:2]
# IDs
The solution I came up with years ago for drawing holes is to make sure that after each hole your x,y coordinates return to the same place. This stops the line buzzing all around and crossing other polygons and leaving open areas that the winding number algorithm doesn't fill (or does fill when it shouldn't).
So, if you have a data set where the first 27 points are your outer, and then you've got three holes of 5, 6, and 7 points, construct a new dataset which is:
newdata = data[c(1:27,28:32,27,33:38,27,39:45,27),] # untested
note how it jumps back to point 27 after each hole. Make sure your holes go in the clockwise direction (I think).
Then draw using newdata but only filling, not drawing outlines. If you want outlines, add them later (using the original data grouped by ring id)
You can sometimes get very very thin artifacts where the outgoing line to the hole isn't quite drawn the same as the incoming line, but they are hardly noticeable. Blame Bresenham.
Try this one
ggplot(datapoly, aes(x=x, y=y)) +
geom_polygon(aes(group=id, fill=factor(value))) +
scale_fill_discrete("Key")