geom_timeline: A geom for adding a timeline plot This geom plots a timeline,...

Description Usage Arguments Details Aesthetics Examples

View source: R/geom.R

Description

A geom for adding a timeline plot This geom plots a timeline, with circles showing the dates when the event occurred. It is intended for the purposes of graphically exploring the NOAA Significant Earthquake Database (included in this package) but can show any data with a column of valid date objects

Usage

1
2
3
geom_timeline(mapping = NULL, data = NULL, stat = "timeline",
  position = "identity", na.rm = FALSE, show.legend = NA,
  inherit.aes = TRUE, x_min = NULL, x_max = NULL, ...)

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

(optional) Stat Override the default Stat transformation of 'timeline'

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.

x_min

(optional) A Date object of the earliest data to be plotted

x_max

(optional) A Date object of the latest data to be plotted

...

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.

Details

This is a general purpose timeline plotting geom, particularly tuned to the NOAA Significant Earthquake Database included with this package. Each event with an associated date will be plotted as a circle on the timeline, so long as the event lies between x_min and x_max. Additional optional aesthetics make the geom much more useful. An optional y aesthetic allows the comparison of different timelines over the same range. Size can show how big an event was (such as an earthquake), and color/fill and alpha can convey yet more information

Aesthetics

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

Examples

1
2
3
4
5
6
7
8
9
data('clean_NOAA')
NOAA <- clean_NOAA
plot_NOAA <- NOAA[NOAA$COUNTRY=="USA" | NOAA$COUNTRY=="CANADA",]
xmin <- lubridate::ymd("2010-01-01")
xmax <- lubridate::ymd("2017-07-01")
plt <- ggplot2::ggplot(data = plot_NOAA, ggplot2::aes(x = DATE, y = COUNTRY)) +
  geom_timeline(ggplot2::aes(size = EQ_PRIMARY), x_min = xmin, x_max = xmax) +
  ggplot2::theme_minimal()
print(plt)

gravatarsmiley/capstoneR documentation built on May 30, 2019, 4:06 a.m.