Description Usage Arguments Details Examples
geom_timeline()
adds the timeline geom to a ggplot2 plot,
geom_timeline_label()
adds labels to the largest earthquakes, and
theme_timeline()
applies formatting to timeline plots. See
"Details".
1 2 3 4 5 6 7 8 9 | geom_timeline(mapping = NULL, data = NULL, stat = "identity",
position = "identity", na.rm = TRUE, show.legend = NA,
inherit.aes = TRUE, ...)
geom_timeline_label(mapping = NULL, data = NULL, stat = "identity",
position = "identity", ..., na.rm = TRUE, n_max = NULL,
show.legend = NA, inherit.aes = TRUE)
theme_timeline(base_size = 12, base_family = "")
|
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. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
other arguments passed on to |
n_max |
an optional integer to label n_max number of largest (by magnitude) earthquakes. |
base_size |
base font size |
base_family |
base font family |
geom_timeline()
is a ggplot2 geom for plotting a time line of
earthquakes ranging from xmin to xmax dates with a point for each
earthquake. Optional aesthetics include color, size, and alpha (for
transparency). The x aesthetic is a date and an optional y aesthetic is a
factor indicating some stratification in which case multiple time lines
will be plotted for each level of the factor (e.g. country).
geom_timeline_label()
is used for adding annotations to the
earthquake data. This geom adds a vertical line to each data point with a
text annotation (e.g. the location of the earthquake) attached to each
line. Aesthetics are x, which is the date of the earthquake and label which
takes the column name from which annotations will be obtained.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | library(ggplot2)
library(dplyr)
library(stringr)
# load data
filename <- system.file("extdata/earthquakes.tsv.gz", package = "quakeR")
raw_data <- readr::read_delim(filename, delim = "\t")
clean_data <- eq_clean_data(raw_data)
# plot timeline
clean_data %>%
mutate_at(vars(DEATHS, EQ_PRIMARY), as.numeric) %>%
filter(str_detect(str_to_lower(COUNTRY), "china|usa$|pakistan")) %>%
filter(DATE >= "2000-01-01") %>%
ggplot(aes(x = DATE,
y = COUNTRY,
size = EQ_PRIMARY,
fill = DEATHS))+
geom_timeline()+
geom_timeline_label(aes(label = LOCATION_NAME,
n_max_var = DEATHS),
n_max = 5)+
theme_timeline()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.