Skip to Content

geom_polygon with multiple hole

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 and values to use for fill colour
values <- data.frame(
  id = ids,
  value = c(4,5)
)
 
# Polygon position
positions <- data.frame(
  id = c(rep(ids, each = 10),rep("b",5)),
  #     shape      hole         shape        hole
  x = c(1,4,4,1,1, 2,2,3,3,2,   5,10,10,5,5, 6,6,7,7,6, 8,8,9,9,8),
  y = c(1,1,4,4,1, 2,3,3,2,2,   5,5,10,10,5, 6,7,7,6,6, 8,9,9,8,8)
)
 
# Merge positions and values
datapoly <- merge(values, positions, by=c("id"))
 
chart <- ggplot(datapoly, aes(x=x, y=y)) + 
  geom_polygon(aes(group=id, fill=factor(value)),colour="grey") +
  scale_fill_discrete("Key")

And gives the following output:

There is a line passing through the two colored boxes, which I don't quite like it, how can I remove that? Thanks.