'How to color lakes and districts in GADM maps?
This might be a trivial question for regular users but I still couldn't find a quick and easy answer. I'm trying to create a map of Uganda in R using data retrieved using the getData("GADM", ...)-command. Here is the map created by the code from below:
I would like to color the countries' lakes in blue and the Kabarole district in red (at the moment there are several observations marked within this district but I would prefer to color the entire district). Can somebody tell me how this can be achieved?
library(Rcpp)
library(raster)
library(ggplot2)
library(ggspatial)
library(cowplot)
uganda <- raster::getData('GADM', country='UGA', level=1)
kampala <- data.frame(name="Kampala", long=32.5833, lat=0.31666)
fort <- data.frame(name="Fort Portal", long=30.274444, lat=0.654444)
ggplot() +
geom_sf() +
geom_polygon(data = uganda,
aes(x = long, y = lat, group = group),
colour = "grey10", fill = "cornsilk", linetype = 2) +
geom_point(data = locations,
aes(x = Longitude, y = Latitude),
colour = "red",
shape = 24,
size = 0.5) +
geom_point(data = kampala,
aes(x=long, y=lat),
colour="black",
size=2.5) +
geom_rect(aes(xmin = 29.8,xmax = 30.6,ymin = 0.2,ymax = 1),
colour = "black",
fill = NA,
size = 1.5,
linetype = 1) +
annotate(geom = "text", x = 32.5833, y = 0.5, label = "Kampala",
fontface = "bold", color = "black", size = 4.5) +
annotate(geom = "text", x = 33.2, y = -0.5, label = "Lake Victoria",
fontface = "italic", color = "grey22", size = 4) +
annotation_scale(data = uganda, location = "bl", width_hint = 0.5) +
annotation_north_arrow(location = "tl",
pad_x = unit(0.75, "in"), pad_y = unit(0.5, "in"),
style = north_arrow_fancy_orienteering) +
coord_sf(crs = sf::st_crs(4326)) +
theme(panel.grid.major = element_line(color = gray(.5), linetype = 'dashed', size = 0.5),
panel.background = element_rect(fill = 'white'),
panel.border = element_rect(colour = "black", fill=NA)) +
xlab("") +
ylab("")
Cross-posted here: https://gis.stackexchange.com/posts/427691/edit
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

