How can I add a color to my dataframe for mapping?

I am not sure how to word this, but I am creating a map on R that will map the city names onto a map of TZ, and I need help to change the name of each city to a different colour when displayed on the map. but that doesn't work. (I am not familiar with R, and did some research but couldn't find a solution.

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

Hi @EllieJay. You can try adding color = city_name within aes() of geom_text().

geom_text(data = city_data, mapping=aes(x=lon, y=lat, label=city_name, color = city_name), nudge_y = 0.5)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.