基本思想很简单:您需要将填充和颜色映射到整个绘图的美感,然后只需将颜色映射到较小多边形的美感,这样您就可以为较小的多边形着色与该颜色相同的颜色的更大的多边形。这就是摆脱较小多边形的内线的原因。然后我在较小多边形的美学之外添加了尺寸,以便将红线的宽度增加到可感知的水平。
plot_data <- load("plot_data.rdata")
library(ggplot2)
df<-plot_data %>%
filter(!is.na(ethnic)) %>% # subset data with ethnicity only
as.data.frame()
ggplot(plot_data,
aes(x= long, y = lat, group = id,fill="", color="")) +
geom_polygon() +
geom_polygon(data = df,
aes(color = ethnic), size=1) +
geom_polygon(data=df, aes(x= long, y = lat, group = id))+
scale_fill_manual(values="black", guide=F)+
scale_color_manual(name="ethnic",
labels=c("","Shaygiyya, Ja'aliyyin and Danagla (Arab)"),
values=c("black","red"),
breaks = c("NA","Shaygiyya, Ja'aliyyin and Danagla (Arab)")) +
coord_equal()
我的会话信息:
sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.5 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_0.12.7 XML_3.98-1.4 proj4_1.0-8 bitops_1.0-6
[5] MASS_7.3-45 grid_3.3.1 plyr_1.8.3 gtable_0.2.0
[9] scales_0.4.0 KernSmooth_2.23-15 ggplot2_2.1.0 ash_1.0-15
[13] RColorBrewer_1.1-2 RJSONIO_1.3-0 tools_3.3.1 RSelenium_1.4.2
[17] munsell_0.4.3 RCurl_1.95-4.8 maps_3.1.0 colorspace_1.2-6
[21] caTools_1.17.1
更新: OP 在使用我发布的代码生成相同的情节时遇到了麻烦。我的一个朋友使用我在此处提供的相同代码在 Windows 系统(我在 El Capitan)上重现了该图,他得到了相同的结果(如下)。