The fanchart is obtained by overlaying ggplot2::geom_ribbon()
of different widths
(corresponding to different levels).
This function is not a geom.
Usage
add_fanchart(
df,
aes_x = "Time",
aes_ymin = "Lower",
aes_ymax = "Upper",
aes_fill = "Level",
legend_fill = c("continuous", "discrete"),
labs_fill = ifelse(legend_fill == "continuous", "Confidence level", "Probability"),
palette = c("#EFF3FF", "#C6DBEF", "#9ECAE1", "#6BAED6", "#3182BD", "#08519C")
)
Arguments
- df
Data with columns
aes_x
,aes_ymin
,aes_ymax
andaes_fill
- aes_x
Name of the
x
aesthetic- aes_ymin
Name of the
ymin
aesthetic- aes_ymax
Name of the
ymax
aesthetic- aes_fill
Name of the
fill
aesthetic- legend_fill
Whether the legend should be displayed as
continuous
or asdiscrete
categories- labs_fill
Name to give to the legend
- palette
Colour palette to use. The default is the single-hue blue palette from
RColorBrewer::brewer.pal(n = 6, "Blues")
.
Alternative
A similar result can be obtained using ggdist::geom_lineribbon()
,
with the difference that the ggdist
function also plots a point estimate (and is a proper geom).
To avoid plotting the point estimate, size
can be set to 0 and y = .lower
for example.