Skip to content

Instantly share code, notes, and snippets.

@jthomasmock
Last active June 21, 2022 21:53
Show Gist options
  • Select an option

  • Save jthomasmock/e28eb77e22048e264a0449adb15fed8b to your computer and use it in GitHub Desktop.

Select an option

Save jthomasmock/e28eb77e22048e264a0449adb15fed8b to your computer and use it in GitHub Desktop.
``` r
library(tidyverse)
df <- palmerpenguins::penguins
ex_df <- df |>
group_by(species) |>
summarise(
n = n(),
mean = mean(body_mass_g, na.rm = TRUE),
sd = sd(body_mass_g, na.rm = TRUE),
body_mass_g = pmap(list(n, mean, sd), rnorm)
) |>
unnest_longer(body_mass_g)
ggplot(df, aes(x = body_mass_g)) +
geom_histogram(aes(y = ..density..),binwidth = 150, color = "white") +
geom_density(data = ex_df, color = "red", size = 1) +
facet_wrap(~species)
#> Warning: Removed 2 rows containing non-finite values (stat_bin).
```
![](https://i.imgur.com/HW797gj.png)
<sup>Created on 2022-06-21 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)</sup>
# Gist URL https://gist.github.com/e28eb77e22048e264a0449adb15fed8b
@jthomasmock

jthomasmock commented Jun 21, 2022

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment