geom_timeline_label: Timeline label ggplot2's geom

Description Usage Arguments Details Warning Examples

Description

geom_timeline_label works together with geom_timeline and shows the labels of the higher values for the aesthetic size (e.g., the magnitude of a quake) or the last observations if this aesthetic is omitted.

Usage

1
2
3
4
geom_timeline_label(mapping = NULL, data = NULL, stat = "identity",
  position = "identity", show.legend = NA, inherit.aes = TRUE,
  n_max = 3, line_height = 2/3, fontsize = 3.88, angle = 45,
  na.rm = FALSE, ...)

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.

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.

n_max

Number of labels to be depicted by level. If the aesthetic size is specified, it will be used to show the observations with the highest values. When this aesthetic is omitted, it will display the last observations. Defaults to 3.

line_height

Length (expressed as proportion of the available space) of the vertical lines attached to the text labels. Defaults to 2/3.

fontsize

Size of the font. Defaults to 3.88.

angle

Rotation of the label in degrees; it is counter clockwise. Defaults to 45.

na.rm

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

...

other arguments passed on to the layer function. 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

Parameter line_height should be used with care because as long as it is lower than 1, it will not overlap with other observations.

Warning

When the size aesthetic is supplied, it is important that there is at least one non-missing value for each level in order to work correctly. Otherwise, the timeline labels will not be displayed.

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
45
require(dplyr)
require(ggplot2)

# Before using the geom, we need to tidy the data up.
raw_data <- get_earthquake_data()
clean_data <- eq_clean_data(raw_data)
clean_data <- eq_location_clean(clean_data)

# Quakes in USA
clean_data %>%
  filter(COUNTRY == "USA",
         !is.na(EQ_PRIMARY),
         YEAR %in% 2000:2016) %>%
  ggplot(mapping = aes(x = DATE,
                       size = EQ_PRIMARY,
                       color = TOTAL_DEATHS / 1000,
                       label = LOCATION_NAME)
         ) +
  geom_timeline() +
  # We label the five biggest quakes in size.
  geom_timeline_label(n_max = 5,
                      line_height = 1 / 5) +
  labs(size  = "Richter scale value",
       color = "# deaths",
       y = "") +
  theme_timeline()

# Quakes in USA and China
clean_data %>%
  filter(COUNTRY %in% c("USA", "CHINA"),
         !is.na(EQ_PRIMARY),
         YEAR %in% 2000:2016) %>%
  ggplot(mapping = aes(x = DATE,
                       y = COUNTRY,
                       color = TOTAL_DEATHS / 1000,
                       label = LOCATION_NAME)
         ) +
  geom_timeline() +
  geom_timeline_label(mapping = aes(size = EQ_PRIMARY),
                                    n_max = 5,
                                    line_height = 1 / 10) +
  labs(color = "# deaths in thousands",
       y = "") +
  guides(size = FALSE) +
  theme_timeline()

Cesar-Urteaga/rnoaa documentation built on May 10, 2019, 5:16 a.m.