library(tidyverse)
#> ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
#> ✔ ggplot2 3.4.0 ✔ purrr 1.0.1
#> ✔ tibble 3.1.8 ✔ dplyr 1.0.10
#> ✔ tidyr 1.2.1 ✔ stringr 1.5.0
#> ✔ readr 2.1.3 ✔ forcats 0.5.2
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag() masks stats::lag()
library(covdata)
#>
#> Attaching package: 'covdata'
#>
#> The following object is masked from 'package:datasets':
#>
#> uspop
library(ggforce)
Apple has made aggregated data available on relative trends in use of its Maps data across a range of cities, regions, and countries. Data show relative volume of directions requests per country/region or city compared to a baseline volume on January 13th, 2020. Apple defines the day as midnight-to-midnight, Pacific time. Cities represent usage in greater metropolitan areas and are stably defined during this period. In many countries/regions and cities, relative volume has increased since January 13th, consistent with normal, seasonal usage of Apple Maps. Day of week effects are important to normalize as you use this data. Data that is sent from users’ devices to the Apple Maps service is associated with random, rotating identifiers so Apple does not have a profile of individual movements and searches. Apple Maps has no demographic information about its users, and so cannot make any statements about the representativeness of its usage against the overall population.
apple_mobility
#> # A tibble: 2,254,515 × 7
#> country sub_region subregion_and_city geo_type date trans…¹ score
#> <chr> <chr> <chr> <chr> <date> <chr> <dbl>
#> 1 Albania Total Total country/region 2020-01-13 driving 100
#> 2 Albania Total Total country/region 2020-01-14 driving 95.3
#> 3 Albania Total Total country/region 2020-01-15 driving 101.
#> 4 Albania Total Total country/region 2020-01-16 driving 97.2
#> 5 Albania Total Total country/region 2020-01-17 driving 104.
#> 6 Albania Total Total country/region 2020-01-18 driving 113.
#> 7 Albania Total Total country/region 2020-01-19 driving 105.
#> 8 Albania Total Total country/region 2020-01-20 driving 94.4
#> 9 Albania Total Total country/region 2020-01-21 driving 94.1
#> 10 Albania Total Total country/region 2020-01-22 driving 93.5
#> # … with 2,254,505 more rows, and abbreviated variable name
#> # ¹transportation_type
vec_brks <- c(-50, 0, 50)
vec_labs <- vec_brks + 100
apple_mobility %>%
filter(geo_type == "city", transportation_type == "driving",
subregion_and_city %in% c("New York City", "Paris",
"Istanbul", "Auckland", "Mexico City")) %>%
mutate(over_under = score < 100,
score = score - 100) %>%
ggplot(mapping = aes(x = date, y = score,
group = subregion_and_city,
color = over_under)) +
geom_hline(yintercept = 0, color = "gray40") +
geom_col() +
scale_y_continuous(breaks = vec_brks, labels = vec_labs) +
scale_color_manual(values = c("firebrick", "steelblue")) +
facet_wrap(~ subregion_and_city, ncol = 1) +
guides(color = "none") +
labs(x = "Date", y = "Relative Mobility", title = "Relative Trends in Apple Maps Usage for Driving, Selected Cities",
subtitle = "Data are indexed to 100 for each city's usage on January 13th 2020",
caption = "Data: Apple. Graph: @kjhealy") +
theme_minimal()