Description Usage Arguments Details Aesthetics References Examples
This geom plots a timeline with circles showing the dates when the event occurred.
It is intended for the purposes of graphically exploring the NOAA Significant
Earthquake Database (included in this package), but can show any data with a column
of valid date
objects
1 2 3 |
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 |
xmin |
(optional) A Date object of the earliest data to be plotted |
xmax |
(optional) A Date object of the latest data to be plotted |
... |
other arguments passed on to |
This is a general purpose timeline plotting geom, particularly tuned to
the NOAA Significant Earthquake Database included with this package. Each event
with an associated date will be plotted as a circle on the timeline, so long as
the event lies between x_min
and x_max
.
Additional optional aesthetics make the geom much more useful. An optional
y
aesthetic allows the comparison of different timelines over the same range.
Size can show how big an event was (such as an earthquake), and color/fill and alpha
can convey yet more information
geom_timeline
understands the following aesthetics (required are in bold):
x
y
color
fill
size
alpha
geom_points: https://github.com/tidyverse/ggplot2/blob/master/R/geom-point.r
extending ggplot: https://github.com/tidyverse/ggplot2/blob/master/vignettes/extending-ggplot2.Rmd
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 | library(data.table)
library(ggplot2)
raw_noaa <- as.data.table(noaa_data)
## Build date variable
clean_noaa <- eq_clean_data(raw_noaa)
clean_noaa <- eq_location_clean(clean_noaa)
## Set key to date
setkey(clean_noaa, DATE)
## Pull test set of 5 years
eq_subset <- clean_noaa[DATE >= "2005-01-01" & DATE <= "2010-12-31"]
## Subset to 5 countries
top_countries <- eq_subset[,.N,by = COUNTRY][order(-N)][1:5, COUNTRY]
eq_subset <- eq_subset[COUNTRY %in% top_countries]
## Set country to factor
eq_subset[, COUNTRY := as.factor(COUNTRY)]
## Set earthquake magnitude to numeric
eq_subset[, EQ_PRIMARY := as.numeric(EQ_PRIMARY)]
## Plot all countries on single time line with labels for 20 largest
# earthquakes.
g <- ggplot(data = eq_subset, aes(x = DATE))
g + geom_timeline(xmin = "2005-01-01", xmax = "2010-12-31",
aes(color = DEATHS,size = EQ_PRIMARY)) + geom_timeline_labels(n_max = 20,
aes(label = LOCATION_NAME, magnitude = EQ_PRIMARY)) + theme_earthquake()
## Plot each country on it's own horizontal line with labels for 20 largest
# earthquakes
g <- ggplot(data = eq_subset, aes(x = DATE, y = COUNTRY))
g + geom_timeline(xmin = "2005-01-01", xmax = "2010-12-31",
aes(color = DEATHS, size = EQ_PRIMARY)) + geom_timeline_labels(n_max = 20,
aes(label = LOCATION_NAME, magnitude = EQ_PRIMARY)) + theme_earthquake() +
labs(y = "")
## Plot each country on it's own horizontal line with labels for 20 largest
# earthquakes. Make all circles the same size.
g <- ggplot(data = eq_subset, aes(x = DATE, y = COUNTRY))
g + geom_timeline(xmin = "2005-01-01", xmax = "2010-12-31",
aes(color = DEATHS)) + geom_timeline_labels(n_max = 20,
aes(label = LOCATION_NAME, magnitude = EQ_PRIMARY)) + theme_earthquake() +
labs(y = "")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.