Skip to content

Instantly share code, notes, and snippets.

@WillForan
Created April 6, 2022 20:03
Show Gist options
  • Save WillForan/43d0aa1787087de96eb0448560e62cd7 to your computer and use it in GitHub Desktop.
Save WillForan/43d0aa1787087de96eb0448560e62cd7 to your computer and use it in GitHub Desktop.
density plot with disparate scaling
library(ggplot2)
library(dplyr)
library(cowplot)
theme_set(theme_cowplot())
load("ds2_long.rdata")
# Smith is different than the other two
combine_ds2_long %>% split(.$study) %>% lapply(function(x) summary(x$value)) %>% bind_rows
# Min. `1st Qu.` Median Mean `3rd Qu.` Max. `NA's`
# <table> <table> <table> <table> <table> <table> <table>
# 8.82e-65 1.0000e-03 3.300e-02 1.585343e-01 2.31e-01 9.94e-01 414
# 6.39e-12 8.6000e-02 3.120e-01 3.788611e-01 6.43e-01 9.99e-01 221
# 7.59e-165 6.9025e-14 2.285e-10 4.042874e-09 4.51e-09 3.15e-08 414
density<-ggplot(combine_ds2_long) +
aes(x=value,colour=study,fill=study) +
geom_density(position="identity") +
facet_wrap(~study, scale="free")
density_zscore <- combine_ds2_long %>% group_by(study) %>% mutate(value_z=scale(value)) %>%
ggplot() +
aes(x=value_z,colour=study,fill=study) +
geom_density(alpha=.4)
plot_grid(density,density_zscore, nrow=2)
@WillForan
Copy link
Author

image

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