knitr::opts_chunk$set(echo = TRUE)

Function: eq_clean_data Description: Cleans raw data by creating a date column with year, month and day in one date, converting LATITUDE and LONGITUDE columns to numeric and cleaning the LOCATION_NAME column with the eq_location_clean() function. Negative years have been removed.

Example:

df <- load_data() \%>\% dplyr::filter(YEAR >= 0) \%>\%
       dplyr::mutate(date = get_date(DAY, MONTH, YEAR))
  print(class(df))
  head(df)

Function: eq_create_label Description: Input a dataframe (df) and the function will output a vector with HTML column names Required columns: CLEAN_LOCATION_NAME, EQ_PRIMARY and DEATHS

Example:

map2 <-load_data() \%>\%
  eq_clean_data() \%>\%
  dplyr::filter(COUNTRY == "GREECE" & lubridate::year(date) >= 2002) \%>\%
  dplyr::mutate(popup_text = eq_create_label(.)) \%>\%
  eq_map(annot_col = "popup_text")
print(map2)

Function: eq_location_clean Description: This function cleans the LOCATION_NAME column by removing country name and converting names to title case.

Example:

df <- load_data() \%>\% eq_location_clean()
  print(class(df))
  head(df)

Function: eq_map Description: Subset of earthquake data plotted on a map using leaflet. Input dataframe requires LONGITUDE, LATITUDE and EQ_PRIMARY columns. Other required argument: annotation column ('annot_col')

Example:

 map1 <-load_data() \%>\%
   eq_clean_data() \%>\%
   dplyr::filter(COUNTRY == "GREECE" & lubridate::year(date) >= 2002) \%>\%
   eq_map(annot_col = "date")
 print(map1)

Function: geom_timeline Description: This geom charts a timeline of earthquakes for a given country with points along the timeline for each earthquake. The size of the point inicates the magnitude of the earthquake, while the color indicates the number of deaths. The date (x) is a required aesthetic. The country (y) is optional.

Example:

 df <- df_earthquakes \%>\% filter(COUNTRY \%in\% c("GREECE", "USA"), YEAR > 2002)
 ggplot(df, aes(x = date, y = COUNTRY,
                color = as.numeric(TOTAL_DEATHS),
                size = as.numeric(EQ_PRIMARY),
                label = CLEAN_LOCATION_NAME)) +
   geom_timeline() +
   labs(size = "Richter scale value", color = "# deaths") +
   ggplot2::theme(panel.background = ggplot2::element_blank(),
         legend.position = "bottom",
         axis.title.y = ggplot2::element_blank()) +
   ggplot2::xlab("DATE")

Function: geom_timeline_label Description: Run geom_timeline first to create timeline. This geom will add a vertical line and label to those points.

Example:

ggplot(df, aes(x = date, y = COUNTRY,
               color = as.numeric(TOTAL_DEATHS),
               size = as.numeric(EQ_PRIMARY),
               label = CLEAN_LOCATION_NAME)) +
  geom_timeline() +
  labs(size = "Richter scale value", color = "# deaths") +
  ggplot2::theme(panel.background = ggplot2::element_blank(),
        legend.position = "bottom",
        axis.title.y = ggplot2::element_blank()) + ggplot2::xlab("DATE") +
  geom_timeline_label(data=df)

Function: GeomTimeline Description: The GeomTimeline charts a timeline of earthquakes for a given country with points along the timeline for each earthquake. The size of the point inicates the magnitude of the earthquake, while the color indicates the number of deaths. The date (x) is a required aesthetic. The country (y) is optional.

Example:

df <- df_earthquakes \%>\% filter(COUNTRY \%in\% c("GREECE", "USA"), YEAR > 2002)
 ggplot(df, aes(x = date, y = COUNTRY,
                color = as.numeric(TOTAL_DEATHS),
                size = as.numeric(EQ_PRIMARY),
                label = CLEAN_LOCATION_NAME)) +
   geom_timeline() +
   labs(size = "Richter scale value", color = "# deaths") +
   ggplot2::theme(panel.background = ggplot2::element_blank(),
         legend.position = "bottom",
         axis.title.y = ggplot2::element_blank()) +
   ggplot2::xlab("DATE")

Function: GeomTimelineLabel Description: The GeomTimelineLabel will add a vertical line and label to those points.

Example:

ggplot(df, aes(x = date, y = COUNTRY,
               color = as.numeric(TOTAL_DEATHS),
               size = as.numeric(EQ_PRIMARY),
               label = CLEAN_LOCATION_NAME)) +
  geom_timeline() +
  labs(size = "Richter scale value", color = "# deaths") +
  ggplot2::theme(panel.background = ggplot2::element_blank(),
        legend.position = "bottom",
        axis.title.y = ggplot2::element_blank()) + ggplot2::xlab("DATE") +
  geom_timeline_label(data=df)

Function: get_date Description: Takes the three date-related columns and turns them into one cohesive date column. Some instances of DAY and MONTH are NA. NA days will be replaced with 1, NA months will be replaced with Jan. Negative years have been removed.

Example:

df <- load_data() \%>\% dplyr::filter(YEAR >= 0) \%>\%
       dplyr::mutate(date = get_date(DAY, MONTH, YEAR))
  print(class(df))
  head(df)

Function: load_data Description: Function loads raw, tab delimited data (from NOAA, in data folder).

Example:

df <- load_data()
  print(class(df))
  head(df)

Function: plot_earthquakes_timeline Description: This plots and formats the earthquake data. The plot will be saved as earthquakes_timeline.png if save_png = TRUE.

Example:

df <- df_earthquakes \%>\%
  filter(COUNTRY \%in\% c("GREECE", "USA"), YEAR > 2002)
plot_earthquakes_timeline(df, save_png=TRUE)

Function: plot_earthquakes_timeline_label Description: This plots and formats the earthquake data, with the addition of labels for the points along the timeline. The plot will be saved as earthquakes_timeline_label.png if save_png = TRUE.

Example:

df <- df_earthquakes \%>\%
  filter(COUNTRY \%in\% c("GREECE", "USA"), YEAR > 2002)
plot_earthquakes_timeline_label(df, save_png=TRUE)


lakrobinson/noaar2 documentation built on Dec. 1, 2020, 9:35 p.m.