stat_fan | R Documentation |
A fan plot consist of a set of transparent ribbons each representing a
different coverage of the uncertainty around an estimate.
The coverages are based on the assumption of a normal distribution with mean
link(y)
and standard error link_sd
.
stat_fan(
mapping = NULL,
data = NULL,
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
geom = "ribbon",
...,
link = c("identity", "log", "logit"),
max_prob = 0.9,
step = 0.05
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom |
Use a different |
... |
Other arguments passed on to
|
link |
the link function to apply on the |
max_prob |
The coverage of the widest band.
Defaults to |
step |
the step size between consecutive bands.
The function adds all bands with coverage |
Other ggplot2 add-ons:
scale_effect()
,
stat_effect()
set.seed(20191218)
z <- data.frame(
year = 1990:2019,
dx = rnorm(30, sd = 0.2),
s = rnorm(30, 0.5, 0.01)
)
z$index <- 3 + cumsum(z$dx)
library(ggplot2)
ggplot(z, aes(x = year, y = index, link_sd = s)) + stat_fan()
ggplot(z, aes(x = year, y = index, link_sd = s)) + stat_fan() + geom_line()
ggplot(z, aes(x = year, y = index, link_sd = s)) + stat_fan(step = 0.3)
ggplot(z, aes(x = year, y = exp(index), link_sd = s)) +
stat_fan(link = "log") + geom_line()
ggplot(z, aes(x = year, y = plogis(index), link_sd = s)) +
stat_fan(link = "logit") + geom_line()
ggplot(z, aes(x = year, y = index, link_sd = s)) + stat_fan(geom = "rect")
ggplot(z, aes(x = year, y = index, link_sd = s)) + stat_fan(geom = "bar")
ggplot(z, aes(x = year, y = index, link_sd = s)) +
stat_fan(geom = "errorbar")
ggplot(z, aes(x = year, y = index, link_sd = s)) +
stat_fan(geom = "linerange")
ggplot(z, aes(x = year, y = index, link_sd = s)) +
stat_fan(geom = "pointrange")
z <- expand.grid(year = 1990:2019, category = c("A", "B"))
z$dx <- rnorm(60, sd = 0.1)
z$index <- rep(c(0, 2), each = 30) + cumsum(z$dx)
z$s <- rnorm(60, rep(c(0.5, 1), each = 30), 0.05)
ggplot(z, aes(x = year, y = index, link_sd = s)) + stat_fan() + geom_line() +
facet_wrap(~category)
ggplot(z, aes(x = year, y = index, link_sd = s)) +
stat_fan(aes(fill = category)) + geom_line(aes(colour = category))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.