set.seed(123456) # for reproducibility
pacman::p_load(tidyverse, psych)
pacman::p_load(ggpubr, gghalves, knitr, cowplot, ggbeeswarm)
pacman::p_load(rstatix, permuco, Superpower, MPTinR, MKinfer, boot)
pacman::p_load_gh("RLesur/klippy", "mitchelloharawild/icons")
options(knitr.kable.NA = '')
options(dplyr.summarise.inform=FALSE) # suppress warning in regards to regrouping
klippy::klippy()
nsims <- 1e4
## Excluding Ss
rm_subject <- function(df, rx){
for (i in rx){
df <- df %>% filter(SID != i) %>% droplevels()
}
cat(sprintf('%d removed & %d left',
length(unique(rx)),
length(unique(df$SID))))
return(df)
}
## Plot
# stat summary plot to 25% quartile and 75% quartile
# https://bit.ly/3iFpV07
single_raincloud_plot <- function(df, Y, xMin, xMax, xBy, xLab){
df %>% ggplot(aes(x = 1, y = Y)) +
geom_half_violin(aes(y = Y), side = "r",
color = "grey70", fill = "grey70") +
geom_half_point(aes(y = Y), side = "l", size = 2,
color = "grey50", fill = "grey50", alpha = .5) +
geom_pointrange(stat = "summary",
fun.min = function(z) {quantile(z,0.25)},
fun.max = function(z) {quantile(z,0.75)},
fun = median, color = "darkred", size = 1) +
scale_y_continuous(breaks=seq(xMin,xMax,by=xBy)) +
coord_flip(ylim = c(xMin, xMax), clip = "on") +
labs(y = xLab) +
theme_bw(base_size = 18) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank(),
aspect.ratio = .3)
}
Procedure
ggdraw() + draw_image("fig/Fig_proc.png")
