Description Usage Format Examples
This function creates the ggproto Geom object to plot the necessary grid grob for
geom_timeline_labels
1 |
An object of class GeomTimelineLabels
(inherits from Geom
, ggproto
) of length 5.
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.