I need help figuring out how to color code a map using coordinates ? If possible, i did research but I couldn't find code to help me. Below in the code I mapped several cities of a country and I need help with a code that would allow me to color the different area where the cities are located.
(if thats not possible, how can I change the color of the cities name, so each city has a different color name instead of all being blue)
library(sf) #'simple features' package
library(leaflet) # web-embeddable interactive maps
library(ggplot2) # general purpose plotting
library(rnaturalearth) # map data
library(rnaturalearthdata)# map data
library(ggspatial) # scale bars and north arrows
#the package below was installed from source through github:
# devtools::install_github("ropensci/rnaturalearthhires"))
library(rnaturalearthhires)# map data
theme_set(theme_bw())
city_data <- data.frame(city_name=c("Dar es Salaam", "Mwanza", "Arusha", "Dodoma", "Mbeya"))
city_data$lat <- c(-6.7924,-2.5164,-3.3869,-6.1630,-8.9094)
city_data$lon <- c(39.2083,32.9175,36.6830,35.7516,33.4608)
ggplot(data = tanzania) +
geom_sf() +
xlab("Longitude") + ylab("Latitude") +
ggtitle("Major Cities in the United Republic of Tanzania") +
annotation_scale(location = "bl", width_hint = 0.4) +
annotation_north_arrow(location = "bl", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
geom_point(data = city_data, mapping = aes(x = lon, y = lat), colour = "red") +
geom_text(data = city_data, mapping=aes(x=lon, y=lat, label=city_name), nudge_y = 0.5, color="darkblue"