我参考了这个问题的答案并有其他问题。
我已将代码修改如下:
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")
并给出以下输出:
有一条线穿过两个彩色框,我不太喜欢它,我该如何删除它?谢谢。