# NOT RUN {
library(ggplot2)
# static plots, need to set group aesthetic manually
ggplot(mtcars, aes(hp, mpg)) +
geom_point() +
stat_smooth_draws(aes(group = stat(.draw)), size = 0.5) +
theme_bw()
# if we want to group by multiple variables, we have to use their
# mapped name (here, `colour` instead of `Species`) because we're
# creating the groups after after initial data mapping
ggplot(iris, aes(Sepal.Length, Sepal.Width, colour = Species)) +
geom_point() +
stat_smooth_draws(
formula = y ~ x,
aes(group = interaction(stat(.draw), colour)),
size = 0.5
) +
theme_bw()
# }
# NOT RUN {
# animated plots
library(gganimate)
ggplot(mtcars, aes(hp, mpg)) +
geom_point() +
stat_smooth_draws(size = 0.5) +
transition_states(stat(.draw), 1, 2)
ggplot(iris, aes(Sepal.Length, Sepal.Width, colour = Species)) +
geom_point() +
stat_smooth_draws(formula = y ~ x, times = 20, size = 0.5) +
transition_states(stat(.draw), 1, 2)
# }
Run the code above in your browser using DataLab