Description Value See Also Examples
GeomTimeline
is a ggplot2
geom
prototype
object for timelines. The geom plots a time line of earthquakes ranging
from xmin
to xmax
dates with a marker 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 stratification in which case multiple time lines will be plotted for each
level of the factor (e.g. country).
GeomTimeline
is a ggplot2
prototype object; a collection of
functions and does not return anything perse. In design pattern parlance,
GeomTimeline
represents a geometry strategy.
geom_timeline
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 46 47 48 49 50 51 52 | library(quake )
library(magrittr )
library(data.table)
library(ggplot2 )
# Create dummy data
n <- 100 # start with 100 data samples
countries <- c("USA", "China", "India", "South Africa")
dt <- data.table(
date = as.Date('2017-01-01') + seq(1, 365, 365/n),
country = factor(sample(countries, replace = TRUE, size = n)),
intensity = runif(n)*10, # mag is somewhere beteen 0 and 10
deaths = runif(n)*12
)
head(dt) # show dummy data
start_date <- as.Date('2017-07-01') # only show quakes from July 2017
end_date <- as.Date('2017-07-30') # only show quakes from July 2017
no_labels_toshow <- 3 # show only three labels from highest intensity quakes
dt %>%
ggplot() +
geom_timeline_label(
aes(
label = as.character(country),
x = date ,
y = country ,
size = intensity
),
n_max = no_labels_toshow,
xmin = start_date,
xmax = end_date
) +
geom_timeline(
aes(
x = date ,
y = country ,
size = intensity,
col = deaths
),
xmin = start_date,
xmax = end_date,
alpha = 0.8
) +
labs(x = "DATE") +
scale_size_continuous (name = "Richter scale value") +
scale_color_continuous(name = "# deaths" ) +
theme_classic() +
theme_timeline_with_y_axis_text
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.