#' corona_map
#'
#' @param d date to extract
#' @param corona_m data frame with corona virus cases
#' @param world world map
#'
#' @importFrom grDevices heat.colors
#'
#' @export
corona_map <- function(d, corona_m, world){
corona_extract <- corona_m[corona_m$date == d,]
m_extract <- match(corona_extract$location, world$geounit)
corona <- rep(NA, length(world$geounit))
corona[m_extract] <- corona_extract$total_cases
corona <- corona/(world$pop_est/1000000)
corona[is.na(corona)] <- 0
coronaC <- cut(corona,
breaks = c(0, 0.000001, 1, 10, 40, 100, 500, 1000, 10000),
include.lowest = TRUE)
levels(coronaC) <- c("Not Reported", "<1", "1-10", "11-40", "41-100",
"101-500", "501-1000", ">1000")
world[,"coronaC"] <- coronaC
cols <- c("white", rev(heat.colors(7)))
# Binned
gworld <- ggplot(data = world) +
geom_sf(aes(fill = coronaC)) +
labs(fill = "Cumulative number of \n COVID-19 cases per million") +
scale_fill_manual(values = cols, drop = FALSE) +
guides(fill = guide_legend(reverse = TRUE)) +
ggtitle(d) + theme(plot.title = element_text(size=22))
gworld
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.