Description Usage Arguments Aesthetics References Examples
This geom labels the timeline created from geom_timeline
.
It draws vertical lines up from the points on the timeline, with labels
for the particular event.
You have the option of only labeleing the top n_max
number of events
sorted by a specified variable
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 |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
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. |
inherit.aes |
If |
n_max |
The top |
... |
other arguments passed on to |
geom_timeline
understands the following aesthetics (required are in
bold):
x
label
The labels to be added
y
magnatude
The feature whose value determines the top
n_max
to be labeled
color
fill
size
alpha
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.