Description Usage Arguments Value Examples
This function (geom_timeline_label) subsets the data to values between xmin and xmax using the filter_ function from the dplyr package (filter_
).
Uses the layer function from the ggplot2 package to call the geomtimeline geom and use it on the data.
1 2 3 |
mapping |
Set of aesthetic mappings created by aes or aes_; If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot; You must supply mapping if there is no plot mapping; Required aes: Date field - x, lowest date to include - xmin, highest date to include - xmax, variable holding labels - label; Default aes: Group variable where separate timelines should be created for each unique value - y; variable where values distinguished by point size - size. |
data |
The data to be displayed in this layer. There are three options: If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot. A data.frame, or other object, will override the plot data; All objects will be fortified to produce a data frame; See fortify for which variables will be created; A function will be called with a single argument, the plot data; The return value must be a data.frame, and will be used as the layer data. |
stat |
Statistical transformation to use on the data. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to layer; These are often aesthetics, used to set an aesthetic to a fixed value, like color = "red" or size = 3; They may also be parameters to the paired geom/stat. |
na.rm |
If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed. |
n_max |
If specified it gives the maximum number of labels to show for each timeline displayed. |
show.legend |
Logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped; FALSE never includes, and TRUE always includes. |
inherit.aes |
If FALSE, overrides the default aesthetics, rather than combining with them; This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders. |
A timeline showing eathquake sizes and intensities between specified dates.
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 53 | ## Not run:
eq_clean_loc_tl <- ggplot(data = eq_clean_loc) +
geom_timeline(aes(x = DATE,
xmin = as.Date("2000-01-01"),
xmax = as.Date("2015-12-31"),
size = EQ_PRIMARY,
fill = TOTAL_DEATHS
)) +
geom_timeline_label(aes(x = DATE,
xmin = as.Date("2000-01-01"),
xmax = as.Date("2015-12-31"),
label = LOCATION_NAME,
size = EQ_PRIMARY),
n_max = 5) +
labs(size = "Richter scale value", fill = "# deaths") +
theme(legend.position="bottom")
eq_clean_loc_tl <- ggplot(data = eq_clean_loc) +
geom_timeline(aes(x = DATE,
xmin = as.Date("2000-01-01"),
xmax = as.Date("2015-12-31"),
y = COUNTRY,
size = EQ_PRIMARY,
fill = TOTAL_DEATHS
)) +
geom_timeline_label(aes(x = DATE,
xmin = as.Date("2000-01-01"),
xmax = as.Date("2015-12-31"),
y = COUNTRY,
label = LOCATION_NAME,
size = EQ_PRIMARY)) +
labs(size = "Richter scale value", fill = "# deaths") +
theme(legend.position="bottom")
eq_clean_loc_tl <- ggplot(data = subset(eq_clean_loc, COUNTRY %in% c("USA" , "CHINA"))) +
geom_timeline(aes(x = DATE,
xmin = as.Date("2000-01-01"),
xmax = as.Date("2015-12-31"),
y = COUNTRY,
size = EQ_PRIMARY,
fill = TOTAL_DEATHS
)) +
geom_timeline_label(aes(x = DATE,
xmin = as.Date("2000-01-01"),
xmax = as.Date("2015-12-31"),
y = COUNTRY,
label = LOCATION_NAME,
size = EQ_PRIMARY),
n_max = 5) +
labs(size = "Richter scale value", fill = "# deaths") +
theme(legend.position="bottom")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.