Since your dput
only shows the result of dput(head(covid))
I decided to plot the map only for the 6 provinces provided.
You can try to use the packages sf
and ggplot2
:
library(rnaturalearth) #get SA map
library(sf)
library(tidyverse)
#Covid data
covid <- structure(list(Province = c("EC", "FS", "GT", "KZ", "LM", "MP"), Cases = c(2748L, 208L, 2993L, 1882L, 132L, 103L), Population = c(11.56,
2.75, 12.27, 10.27, 5.4, 4.04)), row.names = c(NA, 6L), class = "data.frame")
#Map as an sf object
map <- st_as_sf(ne_states(country="South Africa"))
#Modify the covid dataframe before merging
covid <- covid %>%
mutate(name = case_when(Province=="EC" ~ "Eastern Cape",
Province=="FS" ~ "Free State",
Province=="GT" ~ "Gauteng",
Province=="KZ" ~ "KwaZulu-Natal",
Province=="LM" ~ "Limpopo",
Province=="MP" ~ "Mpumalanga"))
#Merging covid data + map
covid <- st_as_sf(left_join(covid,map,by="name"))
#We want to create breaks in order to have the desired legend
covid <- covid %>%
mutate(breaks = case_when(Cases > 45 & Cases < 107 ~ "45 to 107",
Cases > 107 & Cases < 147 ~ "107 to 147",
Cases > 147 & Cases < 1547 ~ "147 to 1547",
Cases > 1547 & Cases < 2846 ~ "1547 to 2846",
Cases > 2846 & Cases < 15396 ~ "2846 or + "))
covid %>%
mutate(breaks=fct_relevel(breaks,"45 to 107","107 to 147","147 to 1547","1547 to 2846","2846 or + ")) %>% #we reorder the labels
ggplot() +
geom_sf(aes(fill=breaks)) +
scale_fill_manual(values=c("#feedde","#fdd0a2","#fd8d3c","#f16913","#d94801")) +
geom_point(aes(x=longitude, y=latitude, size=Population),colour="grey70") +
labs(fill="Cases") +
theme_void()

You can certainly improve the result by using the appropriate coordinate reference system (have a look at the documentation of the sf
package).