From 6948f936231fd3b5faaab1ab22658baf0ed63dd3 Mon Sep 17 00:00:00 2001 From: Nicholas Judd Date: Wed, 4 Dec 2024 17:07:33 +0100 Subject: [PATCH] increased variance of a group for t2 and other minor plot changes --- inst/fig2.R | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/inst/fig2.R b/inst/fig2.R index 697d396..4e50962 100644 --- a/inst/fig2.R +++ b/inst/fig2.R @@ -2,10 +2,10 @@ ## figure creation for 'ggrain' manuscript to Journal of Open Source Software -## Use and pre-load to setwd() all documents in : "Workshop8 - Brain development day" +## Use and pre-load to setwd() all documents in : "Workshop8 - Brain development day" if (!require(pacman)) {install.packages("pacman")} -pacman::p_load(patchwork, tidyverse, ggrain) +pacman::p_load(patchwork, tidyverse, ggrain) ################################################# # first we will start by simulating some data! :) @@ -24,34 +24,43 @@ df <- data.frame(score = c(groupa, groupb), group = c(rep("A", length(groupa)), ## simple figure -p_simple <- ggplot(simdat, aes(x=group,y=score, fill = group, colour = group)) + +p_simple <- ggplot(df, aes(x=group,y=score, fill = group)) + geom_rain(rain.side = "r", - boxplot.args = list(color = "black", outlier.color = NA)) + + point.args = list(alpha = .8), + boxplot.args = list(color = "black", outlier.color = NA)) + scale_color_brewer(palette = "Dark2") + scale_fill_brewer(palette = "Dark2") + - theme_minimal(base_size = 26) + labs(x = "") + + theme_minimal(base_size = 30) # making long data g_A1 <- rnorm(15, 6.5, 2) set.seed(22) -g_A2 <- rnorm(15, 6.5, 2) + rnorm(15) + 1 +g_A2 <- rnorm(15, 6.5, 2) + rnorm(15, 1, 1) + 3 + +g_A1 <- abs(g_A1) # zero cesoring + +g_B1 <- c(rnorm(14, 2, .8), 8.5) +g_B1 <- abs(g_B1) # zero cesoring -g_B1 <- c(rnorm(14, 2, 1), 8.1) set.seed(24) -g_B2 <- c(rnorm(14, 2, 1), 8.9) + rnorm(15) + 1 +g_B2 <- c(rnorm(14, 2, 2), 8.9) + rnorm(15,1,1) + 3 -df2 <- data.frame(score = c(g_A1, g_A2, g_B1, g_B2), +df2 <- data.frame(score = c(g_A1, g_A2, g_B1, g_B2), id = as.character(c(rep(1:15), rep(1:15), rep(16:30), rep(16:30))), - time = c(rep("1", 15), rep("2", 15), rep("1", 15), rep("2", 15)), + time = c(rep("pre", 15), rep("post", 15), rep("pre", 15), rep("post", 15)), group = c(rep("A", 30), rep("B", 30))) +df2$time <- factor(df2$time, levels = c("pre", "post")) # making a more complex long data fig p_complex <- ggplot(df2, aes(x = time, y = score, fill = group, color = group)) + geom_rain(id.long.var = "id", rain.side = "f2x2", boxplot.args = list(color = "black", outlier.color = NA), - violin.args = list(adjust = 1.5, trim = FALSE)) + + violin.args = list(adjust = 1.5, trim = FALSE, alpha = .5)) + scale_color_brewer(palette = "Dark2") + scale_fill_brewer(palette = "Dark2") + - theme_minimal(base_size = 26) + labs(x = "") + + theme_minimal(base_size = 30) + p_all <- p_simple / p_complex + plot_annotation(tag_levels = "a")