geom_timeline: Geom for NOAA Earthquake dataset

Description Usage Arguments Aesthetics Examples

View source: R/geom-timeline.R

Description

This geom is used to create timelines for the NOAA Significant Earthquakes dataset.

Usage

 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
geom_timeline_label(
  mapping = NULL,
  data = NULL,
  position = "identity",
  show.legend = NA,
  na.rm = FALSE,
  inherit.aes = TRUE,
  ...
)

geom_timeline(
  mapping = NULL,
  data = NULL,
  position = "identity",
  show.legend = NA,
  na.rm = FALSE,
  inherit.aes = TRUE,
  ...
)

stat_timeline_label(
  mapping = NULL,
  data = NULL,
  geom = "timeline_label",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE,
  ...
)

stat_timeline(
  mapping = NULL,
  data = NULL,
  geom = "timeline",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE,
  ...
)

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. A function can be created from a formula (e.g. ~ head(.x, 10)).

position

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

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. It can also be a named logical vector to finely select the aesthetics to display.

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().

geom

The geometric object to use display the data

Aesthetics

geom_timeline() understands the following aesthetics (required aesthetics are in bold):

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
## Not run: 
library(msdrCourseraCapstonePackage)
library(magrittr)
library(ggplot2)
library(dplyr)
library(lubridate)

data_path <- system.file("extdata", "signif.txt", package = "msdrCourseraCapstonePackage")
eq_data_raw <- read.delim(data_path)
eq_data <- eq_clean_data(eq_data_raw)

eq_data_plot <- eq_data %>% filter(COUNTRY %in% c("CANADA", "USA", "MEXICO"))

# basic timeline of entire dataset
ggplot(eq_data_plot, aes(x = DATE)) + geom_timeline() + theme_eq

# filter timeline with a min date
ggplot(eq_data_plot, aes(x = DATE, min_date = as.Date("1900-01-01"))) + geom_timeline() + theme_eq

# add a max date as well
ggplot(eq_data_plot, aes(x = DATE, min_date = as.Date("1900-01-01"), max_date = as.Date("1950-01-01"))) + geom_timeline() + theme_eq

# use y aesthetic to add COUNTRY stratification
ggplot(eq_data_plot, aes(x = DATE, y = COUNTRY, min_date = as.Date("1900-01-01"), max_date = as.Date("1950-01-01"))) + geom_timeline() + theme_eq

# use size and color of points to represent magnitude and number of casualties, and set alpha to 0.3
plot <- ggplot(eq_data_plot, aes(x = DATE, y = COUNTRY, min_date = as.Date("1900-01-01"), max_date = as.Date("1950-01-01"), size = EQ_PRIMARY, color = TOTAL_DEATHS)) + geom_timeline(alpha = 0.3) + theme_eq

## End(Not run)

jtgit-la/msdrCourseraCapstonePackage documentation built on May 10, 2020, 5:01 p.m.