Chapter 5 geom_timeline_label
The geom_timeline_label
is a complementary geom
to aggregate notations to the geom_timeline
. Using this geom
you can add labels to the n_max
most deadly earthquake. The configuration is almost the same of geom_timeline.
- mag: The magnitude of the earthquake;
- label: The Location of the earthquake;
- n_max: Number of earthquake to be highlighted using the notation;
- x axis: This is the temporal axis.
- y axis: Each county has your own line, it is not possible to mix countries in a single y axis.
5.1 Example 1
Let’s plot the earthquake from 1900 to 2000, which occured in CHINA
and TURKEY
.
# Path to the raw data.
raw_data_path <- system.file("extdata", "signif.txt", package = "msdr")
# Loading the dataset of Earthquake.
df <- readr::read_delim(file = raw_data_path,
delim = '\t',
col_names = TRUE,
progress = FALSE,
col_types = readr::cols())
# Cleaning the data and filtering.
df %>%
eq_clean_data() %>%
filter(COUNTRY %in% c('CHINA','TURKEY'),
YEAR >= 1900 &
YEAR <= 2000) %>%
# Creating a ggplot object
ggplot() +
# Using the new Geom
geom_timeline(aes(x = DATE,
y = COUNTRY,
size = EQ_PRIMARY,
color = TOTAL_DEATHS)) +
# Adding notation.
geom_timeline_label(aes(x = DATE,
y = COUNTRY,
mag = EQ_PRIMARY,
label = LOCATION,
n_max = 10)) +
# Adding theme.
theme_msdr() +
# Editing the legends' titles
labs(size = "Richter scale value",
color = "# deaths")