geom_timeline: This method returns a ggplot2 layer that contains the custom...

Description Usage Arguments Value Examples

View source: R/visualization_tools.R

Description

This method returns a ggplot2 layer that contains the custom geom for plotting earthquake data on a timeline. The color aesthetic indicates the number of deaths as a result of the earthquake and the size aesthetic indicates the earthquake magnitude on the Richter scale. A layer is a combination of data, stat and geom with a potential position adjustment.

Usage

1
2
3
geom_timeline(mapping = NULL, data = NULL, stat = "identity",
  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. "x" is the date of the earthquake. "y" is an optional aesthetic indicating a stratification for which a separate timeline will be plotted for each value of the factor (for instance "country"). "size" is the magnitude of the earthquake measured on the Richter scale. "color" is the number of deaths caused by the earthquake.

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

...

Additional parameters passed to the layer.

Value

A ggplot2 layer which contains the custom geom for visualizing earthquake data on a timeline.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
p <- readr::read_delim(file = system.file("extdata", "signif.txt", package="noaa"),
                                          delim = "\t") %>%
     eq_clean_data() %>% eq_location_clean() %>%
     dplyr::filter(YEAR >= 1900, !is.na(DEATHS), !is.na(EQ_MAG_ML),
                   COUNTRY %in% c("CHINA", "USA")) %>%
     ggplot2::ggplot() +
     geom_timeline(ggplot2::aes(x = DATE,
       colour = DEATHS,
       size = EQ_MAG_ML)) +
     ggplot2::labs(x = "DATE", color = "# deaths", size = "Richter scale value")
gt <- ggplot2::ggplot_gtable(ggplot2::ggplot_build(p))
gt$layout$clip[gt$layout$name=="panel"] = "off"
grid::grid.draw(gt)

chrpihl/noaa documentation built on May 25, 2019, 3:26 p.m.