get_spain_regional_cases: Spain regional cases daily

Description Usage Arguments Value Examples

View source: R/get_spain_regional_cases.R

Description

Extract regional spanish case counts. Source

Usage

1
get_spain_regional_cases(dataset = "cases_provincial")

Arguments

dataset

Character String specifying dataset: "cases_provincial", "hospitalisation_provincial", "icu_provincial", "mortality_provincial", "recovered_provincial", "all". Default: "cases_provincial".

Value

A dataframe of specified Covid data. If dataset = "all", a dataframe with all variables (cases, hospitalisation, ICU, mortality, recovered)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
## Not run: 

# Regional map

library(sf)
library(rnaturalearth)
library(ggplot2)

data <- get_spain_regional_cases()

regions <- rnaturalearth::ne_states("Spain", returnclass = "sf")
regions_with_data <- regions %>%
  mutate(region_shortcode = stringr::str_remove_all(region_cod, "^ES\."), # Match codes to dataset
         region_shortcode = stringr::str_replace(region_shortcode, "^PM$", "IB"), # Baleares
         region_shortcode = stringr::str_replace(region_shortcode, "^MU$", "MC"), # Murcia
         region_shortcode = stringr::str_replace(region_shortcode, "^NA$", "NC"), # Navarra
         region_shortcode = stringr::str_replace(region_shortcode, "^LO$", "RI"), # La Rioja
         region_shortcode = ifelse(region == "Melilla", "ME", region_shortcode) # Melilla
  ) %>%
  group_by(region_shortcode) %>%
  summarise(subregions = n(), do_union = TRUE) %>%
  left_join(data, by = c("region_shortcode" = "region"))

# Map: Spain mainland + Baleares
es_mainland <- ggplot2::ggplot(regions_with_data) +
  geom_sf(ggplot2::aes(fill = cases)) +
  coord_sf(crs = st_crs(4326), xlim = c(-11, 4), ylim = c(35, 44))+
  theme_bw()

# Map inset: Canarias
es_canarias <- dplyr::filter(regions_with_data, region == "Canarias")
es_canarias <- ggplot2::ggplot(es_canarias) +
  geom_sf(aes(fill = cases)) +  coord_sf(datum = NA) +
  xlab(es_canarias$region) +
  theme_bw() +  theme(legend.position = "none")

# Map: mainland with insets
es_mainland +
  annotation_custom(
    grob = ggplotGrob(es_canarias),  xmin = -11,  xmax = -7,  ymin = 33.5,  ymax = 37.5)



## End(Not run)

epiforecasts/NCoVUtils documentation built on June 26, 2020, 1:20 a.m.