geom_timeline_labels: A geom for labeling the timeline plot from 'geom_timeline'

Description Usage Arguments Aesthetics References Examples

Description

This geom labels the timeline created from geom_timeline. It draws vertical lines up from the points on the timeline, with labels for the particular event. You have the option of only labeleing the top n_max number of events sorted by a specified variable

Usage

1
2
3
geom_timeline_labels(mapping = NULL, data = NULL, na.rm = TRUE,
  show.legend = NA, stat = "identity", position = "identity",
  inherit.aes = TRUE, n_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.

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.

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.

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.

n_max

The top n_max labels to plot. For example, if earthquake occurrences are being plotted, and you only want to label 5 largest earthquakes, by magnitude, pass 5 here

...

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.

Aesthetics

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

References

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
library(data.table)
library(ggplot2)
raw_noaa <- as.data.table(noaa_data)

## Build date variable
clean_noaa <- eq_clean_data(raw_noaa)
clean_noaa <- eq_location_clean(clean_noaa)

## Set key to date
setkey(clean_noaa, DATE)

## Pull test set of 5 years
eq_subset <- clean_noaa[DATE >= "2005-01-01" & DATE <= "2010-12-31"]

## Subset to 5 countries
top_countries <- eq_subset[,.N,by = COUNTRY][order(-N)][1:5, COUNTRY]
eq_subset <- eq_subset[COUNTRY %in% top_countries]

## Set country to factor
eq_subset[, COUNTRY := as.factor(COUNTRY)]

## Set earthquake magnitude to numeric
eq_subset[, EQ_PRIMARY := as.numeric(EQ_PRIMARY)]

## Plot all countries on single time line with labels for 20 largest
# earthquakes.
g <- ggplot(data = eq_subset, aes(x = DATE))
g + geom_timeline(xmin = "2005-01-01", xmax = "2010-12-31",
  aes(color = DEATHS,size = EQ_PRIMARY)) + geom_timeline_labels(n_max = 20,
  aes(label = LOCATION_NAME, magnitude = EQ_PRIMARY)) + theme_earthquake()
## Plot each country on it's own horizontal line with labels for 20 largest
# earthquakes
g <- ggplot(data = eq_subset, aes(x = DATE, y = COUNTRY))
g + geom_timeline(xmin = "2005-01-01", xmax = "2010-12-31",
  aes(color = DEATHS, size = EQ_PRIMARY)) + geom_timeline_labels(n_max = 20,
  aes(label = LOCATION_NAME, magnitude = EQ_PRIMARY)) + theme_earthquake() +
  labs(y = "")
## Plot each country on it's own horizontal line with labels for 20 largest
# earthquakes. Make all circles the same size.
g <- ggplot(data = eq_subset, aes(x = DATE, y = COUNTRY))
g + geom_timeline(xmin = "2005-01-01", xmax = "2010-12-31",
  aes(color = DEATHS)) + geom_timeline_labels(n_max = 20,
  aes(label = LOCATION_NAME, magnitude = EQ_PRIMARY)) + theme_earthquake() +
  labs(y = "")

marksendak/MsdrCapstoneMPS documentation built on May 23, 2019, 7:33 a.m.