geom_lolli {RmarineHeatWaves} | R Documentation |
Visualise a Timeline of Several Event Metrics as 'Lollipops'.
Description
The function will return a graph of the intensity of the selected
metric along the *y*-axis versus a time variable along the *x*-axis.
The number of top events (n
) from the chosen metric may be highlighted
in a brighter colour with the aesthetic value colour.n
.
This function differs in use from lolli_plot
in that it must be created as a ggplot2 'geom' object. The benefit of this being
that one may add additional information layer by layer to the figure as
geoms as necessary.
Usage
geom_lolli(mapping = NULL, data = NULL, ..., n = 1, na.rm = FALSE,
show.legend = NA, inherit.aes = TRUE)
Arguments
mapping |
Set of aesthetic mappings created by |
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 A data.frame, or other object, will override the plot data. All objects will
be fortified to produce a data frame. See A function will be called with a single argument, the plot data. The return
value must be a |
... |
other arguments passed on to |
n |
The number of top events to highlight. Default is 1. This parameter
has no effect if |
na.rm |
If |
show.legend |
Logical. Should this layer be included in the legends? |
inherit.aes |
If |
Aesthetics
geom_lolli
understands the following aesthetics (required aesthetics
are in bold):
-
x
-
y
-
alpha
-
color
-
linetype
-
size
-
shape
-
stroke
-
fill
-
colour.n
: While this value may be used as an aesthetic, it also works as a parameter for this function. If one chooses not to highlight any events, usecolour.n = NA
outside ofaes()
. One may also provide a non-static value tocolour.na
but remember that one may not provide multiple continuous or discrete scales to a single ggplot2 object. Therefore, if one provides a continuous value toaes(colour)
, the values supplied tocolour.n
must be discrete. ggplot2 will attempt to do this automatically.
Author(s)
Robert W. Schlegel
See Also
lolli_plot
for a non-geom based lolliplot function.
Examples
ts_dat <- make_whole(sst_NW_Atl)
# with defaults:
res <- detect(ts_dat, climatology_start = "1983-01-01",
climatology_end = "2012-12-31")
mhw <- res$event
## Not run:
require(lubridate)
# Height of lollis represent event durations and their colours
# are mapped to the events' cumulative intensity:
ggplot(mhw, aes(x = mhw$date_peak, y = mhw$duration)) +
geom_lolli(n = 0, shape = 20, aes(colour = mhw$int_cum), colour.n = NA) +
scale_color_distiller(palette = "Spectral", name = "Cumulative \nintensity") +
xlab("Date") + ylab("Event duration [days]")
# Height of lollis represent event durations and the top three (longest)
# lollis are highlighted in red:
ggplot(mhw, aes(x = mhw$date_peak, y = mhw$duration)) +
geom_lolli(n = 3, shape = 20, colour.n = "red") +
scale_color_distiller(palette = "Spectral", name = "Cumulative \nintensity") +
xlab("Date") + ylab("Event duration [days]")
## End(Not run)