【发布时间】:2014-02-10 12:39:37
【问题描述】:
我有一张波斯尼亚的地图,上面有根据居住在那里的多数族裔而不同颜色的城市。
但是,我想使用不同的图案而不是颜色(或灰度),因为它将以黑白打印。
我已经搜索过,但找不到方法。有谁知道如何做到这一点?
Link to shapefile
到目前为止,这是我的代码:
library(RColorBrewer)
library(maptools)
library(rgdal)
library(rgeos)
library(ggplot2)
library(gridExtra)
setwd("path")
bosnia <- readOGR("path/to/file", "bosnia_analysis",
verbose = TRUE, stringsAsFactors = FALSE)
bosnia <- readShapePoly("path/to/bosnia_analysis.shp",proj4string=CRS("+proj=longlat +datum=WGS84"))
bosnia.df <- bosnia@data
serbs <- bosnia[bosnia$SEPRIORITY > bosnia$CRPRIORITY & bosnia$SEPRIORITY > bosnia$MOPRIORITY,]
croats <- bosnia[bosnia$CRPRIORITY > bosnia$SEPRIORITY & bosnia$CRPRIORITY > bosnia$MOPRIORITY,]
moslems <- bosnia[bosnia$MOPRIORITY > bosnia$CRPRIORITY & bosnia$MOPRIORITY > bosnia$SEPRIORITY,]
p <- ggplot(bosnia, aes(x = long, y = lat, group = group)) +
geom_polygon(aes(x=long,y=lat,group=group), fill="white", colour="grey") +
geom_polygon(data=serbs, aes(x=long,y=lat,group=group), fill="black", colour="grey") +
geom_polygon(data=croats, aes(x=long,y=lat,group=group), fill="green", colour="grey") +
geom_polygon(data=moslems, aes(x=long,y=lat,group=group), fill="red", colour="grey") +
# Styling
coord_map() +
labs(x="Bosnia", y=" ") +
theme_bw() +
theme(panel.grid.minor=element_blank(), panel.grid.major=element_blank()) +
theme(axis.ticks = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank()) +
theme(panel.border = element_blank())
p
这给了我以下地图:
【问题讨论】:
-
你有任何关于 ggplot2 和 shapefile 的初学者文献吗?