Filling geospatial polygons with a pattern - R

I have a map of Bosnia with municipalities colored according to the ethnic majority living there. However, I would like to use different patterns instead of colors (or gray scales), since it will be printed in black and white.
I searched, but could not find a way to do this. Does anyone have an idea on how to do this? Shapefile link

Here is my code:

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

This gives me the following map: enter image description here

+3
source share
1 answer

Ditch ggplotfor basic graphics. Although with three groups I would think that black, white and silver would work fine.

require(sp)
require(rgdal)

bosnia = readOGR(".","bosnia_analysis")
proj4string(bosnia)=CRS("+init=epsg:4326")

, 3 , TRUE/FALSES:

serbs = bosnia$SEPRIORITY > bosnia$CRPRIORITY & bosnia$SEPRIORITY > bosnia$MOPRIORITY
croats =  bosnia$CRPRIORITY > bosnia$SEPRIORITY & bosnia$CRPRIORITY > bosnia$MOPRIORITY
moslems = bosnia$MOPRIORITY > bosnia$CRPRIORITY & bosnia$MOPRIORITY > bosnia$SEPRIORITY

bosnia$group=NA
bosnia$group[serbs]="Serb"
bosnia$group[croats]="Croat"
bosnia$group[moslems]="Moslem"
bosnia$group=factor(bosnia$group)

, :

sum(serbs&&croats&&moslems) # should be zero

, :

spplot(bosnia, "group")

, mono, :

plot(bosnia,density=c(5,10,15)[bosnia$group], angle=c(0,45,90)[bosnia$group])

shaded map of Bosnia

. legend .

+11

All Articles