Created
April 2, 2024 05:28
-
-
Save abikoushi/00acd4b9b2f8b7889703f56a80d908f9 to your computer and use it in GitHub Desktop.
geom_function with facet_wrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(ggplot2) | |
set.seed(123) | |
fdf <- expand_grid(year=1:4, generation=1:4) %>% | |
mutate(mu=rnorm(16),sigma=abs(rnorm(16))) | |
layerfun <- split(fdf, interaction(fdf$year, fdf$generation)) %>% | |
lapply(function(x){ | |
geom_function(data = x, | |
fun = dnorm, | |
args = list(mean=x$mu, sd=x$sigma), | |
aes(colour = factor(generation))) | |
}) | |
ggplot(fdf) + | |
layerfun + | |
facet_wrap(~year, nrow = 5) + | |
xlim(-4, 4) | |
ggsave("statfuns.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment