Description Usage Arguments Details Warning Examples
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.
1 2 3 4 |
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
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?
|
inherit.aes |
If |
n_max |
Number of labels to be depicted by level. If the aesthetic
|
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. |
Parameter line_height
should be used with care because as long as it
is lower than 1, it will not overlap with other observations.
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.
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()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.