knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Usage notes

Instead of repeatedly reading in the original data, I included an already cleaned version of the raw data as noaa_data in this package. This is done in data/signif-import.R:

```{R, eval = FALSE} noaa_data <- eq_clean_data("data-raw/signif.txt")

### Visualisation tools: ggplot2 timeline

The following code creates a timeline without annotation.

```{R}
library(rcapstone)
library(dplyr)  # for pipe

plot1 <- noaa_data %>%
  dplyr::filter(DATE > lubridate::ymd("2000-01-01") & DATE < lubridate::ymd("2018-01-01")) %>%
  dplyr::filter(COUNTRY == "USA") %>%
  ggplot2::ggplot(
    mapping = ggplot2::aes(
      x = DATE,
      fill = DEATHS,
      size = EQ_PRIMARY
    )
  ) +
  geom_timeline() +
  ggplot2::labs(fill = "# deaths", size = "Richter scale value") +
  theme_eq()

plot1

The following code creates the same timeline with annotation:

plot2 <- plot1 +
  geom_timeline_label(ggplot2::aes(label = LOCATION, n_max = 5))

plot2
plot3 <- noaa_data %>%
  dplyr::filter(DATE > lubridate::ymd("2000-01-01") & DATE < lubridate::ymd("2018-01-01")) %>%
  dplyr::filter(COUNTRY %in% c("USA", "CHINA")) %>%
  ggplot2::ggplot(
    mapping = ggplot2::aes(
      x = DATE,
      y = COUNTRY,
      fill = DEATHS
    )
  ) +
  geom_timeline() +
  ggplot2::labs(fill = "# deaths") +
  geom_timeline_label(ggplot2::aes(size = EQ_PRIMARY, label = LOCATION, n_max = 5)) +
  ggplot2::scale_size_continuous(guide = FALSE) +
  theme_eq()

  plot3
  ```

### Mapping tools: leaflet map

The following plots the first map that produces simple pop-ups.

```{R}
noaa_data %>%
  dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>%
  eq_map(annot_col = DATE)

As you can see there is a slight difference to how eq_map() is called compared to the original task description. Instead of providing the argument annot_col as string, in my version it can be provided in tidyeval-style.

noaa_data %>%
  dplyr::filter(COUNTRY == "MEXICO" & lubridate::year(DATE) >= 2000) %>%
  dplyr::mutate(popup_text = eq_create_label(.)) %>%
  eq_map(annot_col = popup_text)


niklaas/rcapstone documentation built on May 25, 2019, 10:41 p.m.