geom_timeline: Plot earthquake timelines

Description Usage Arguments Details Examples

View source: R/ggplot_geoms.R

Description

geom_timeline() adds the timeline geom to a ggplot2 plot, geom_timeline_label() adds labels to the largest earthquakes, and theme_timeline() applies formatting to timeline plots. See "Details".

Usage

1
2
3
4
5
6
7
8
9
geom_timeline(mapping = NULL, data = NULL, stat = "identity",
  position = "identity", na.rm = TRUE, show.legend = NA,
  inherit.aes = TRUE, ...)

geom_timeline_label(mapping = NULL, data = NULL, stat = "identity",
  position = "identity", ..., na.rm = TRUE, n_max = NULL,
  show.legend = NA, inherit.aes = TRUE)

theme_timeline(base_size = 12, base_family = "")

Arguments

mapping

Set of aesthetic mappings created by aes or aes_. If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot.

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame., and will be used as the layer data.

stat

The statistical transformation to use on the data for this layer, as a string.

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders.

...

other arguments passed on to layer. These are often aesthetics, used to set an aesthetic to a fixed value, like color = "red" or size = 3. They may also be parameters to the paired geom/stat.

n_max

an optional integer to label n_max number of largest (by magnitude) earthquakes.

base_size

base font size

base_family

base font family

Details

geom_timeline() is a ggplot2 geom for plotting a time line of earthquakes ranging from xmin to xmax dates with a point for each earthquake. Optional aesthetics include color, size, and alpha (for transparency). The x aesthetic is a date and an optional y aesthetic is a factor indicating some stratification in which case multiple time lines will be plotted for each level of the factor (e.g. country).

geom_timeline_label() is used for adding annotations to the earthquake data. This geom adds a vertical line to each data point with a text annotation (e.g. the location of the earthquake) attached to each line. Aesthetics are x, which is the date of the earthquake and label which takes the column name from which annotations will be obtained.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library(ggplot2)
library(dplyr)
library(stringr)

# load data
filename <- system.file("extdata/earthquakes.tsv.gz", package = "quakeR")
raw_data <- readr::read_delim(filename, delim = "\t")
clean_data <- eq_clean_data(raw_data)

# plot timeline
clean_data %>%
  mutate_at(vars(DEATHS, EQ_PRIMARY), as.numeric) %>%
  filter(str_detect(str_to_lower(COUNTRY), "china|usa$|pakistan")) %>%
  filter(DATE >= "2000-01-01") %>%
  ggplot(aes(x = DATE,
             y = COUNTRY,
             size = EQ_PRIMARY,
             fill = DEATHS))+
  geom_timeline()+
  geom_timeline_label(aes(label = LOCATION_NAME,
                          n_max_var = DEATHS),
                      n_max = 5)+
  theme_timeline()

vadimus202/quakeR documentation built on May 19, 2019, 1:47 a.m.