--- tags: Rscripts --- # Violin plots for dependent variables ### Author: Jocelyn P. Colella + These exclude all outliers identified across all DVs (N 430 total, 215 each sex) ## Females #### daytime ![](https://i.imgur.com/Wh64ULG.png) #### nighttime ![](https://i.imgur.com/x4wYdRQ.png) ## Males #### daytime ![](https://i.imgur.com/RMG2mUj.png) #### nighttime ![](https://i.imgur.com/DvgvKJV.png) ``` #Function to calculate medians for plotting data_summary <- function(x) { med <- median(x) m <- mean(x) ymin <- m-sd(x) ymax <- m+sd(x) return(c(y=med,ymin=ymin,ymax=ymax)) } #### FEMALE DAYTIME VIOLINE PLOTS # EE pEE <- all_day_noOL_F %>% ggplot( aes(x=experiment, y=EE, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.title = element_text(size=14)) + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") # RQ pRQ <- all_day_noOL_F %>% ggplot( aes(x=experiment, y=RQ, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + theme(legend.position="none") + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") # VO2 pVO2 <- all_day_noOL_F %>% ggplot( aes(x=experiment, y=VO2, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") #VCO2 pVCO2 <- all_day_noOL_F %>% ggplot( aes(x=experiment, y=VCO2, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") #H2Omg pH2O <- all_day_noOL_F %>% ggplot( aes(x=experiment, y=H2Omg, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") # PLOT ALL DAYTIME FEMALE PLOTS TOGETHER plot_grid(pEE, pRQ, pVO2, pVCO2, pH2O, labels = c('a) EE', 'b) RQ', 'c) VO2', 'd) VCO2', 'e) H2O (mg)'), label_size = 12) ### FEMALE NIGHTTIME VIOLIN PLOTS # EE pEE <- all_night_noOL_F %>% ggplot( aes(x=experiment, y=EE, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + #geom_dotplot(binaxis='y', stackdir='center', dotsize=0.2, binwidth = 0.01) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.title = element_text(size=14)) + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") # RQ pRQ <- all_night_noOL_F %>% ggplot( aes(x=experiment, y=RQ, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + theme(legend.position="none") + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") # VO2 pVO2 <- all_night_noOL_F %>% ggplot( aes(x=experiment, y=VO2, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") #VCO2 pVCO2 <- all_night_noOL_F %>% ggplot( aes(x=experiment, y=VCO2, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") #H2Omg pH2O <- all_night_noOL_F %>% ggplot( aes(x=experiment, y=H2Omg, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + #geom_dotplot(binaxis='y', stackdir='center', dotsize=0.2, binwidth = 0.006) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") # PLOT ALL FEMALE NIGHTITME PLOTS TOGETHER plot_grid(pEE, pRQ, pVO2, pVCO2, pH2O, labels = c('a) EE', 'b) RQ', 'c) VO2', 'd) VCO2', 'e) H2O (mg)'), label_size = 12) ################################################### ###MALE DAYTIME VIOLIN PLOTS # EE pEE <- all_day_noOL_M %>% ggplot( aes(x=experiment, y=EE, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.title = element_text(size=14)) + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") # RQ pRQ <- all_day_noOL_M %>% ggplot( aes(x=experiment, y=RQ, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + theme(legend.position="none") + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") # VO2 pVO2 <- all_day_noOL_M %>% ggplot( aes(x=experiment, y=VO2, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") #VCO2 pVCO2 <- all_day_noOL_M %>% ggplot( aes(x=experiment, y=VCO2, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") #H2Omg pH2O <- all_day_noOL_M %>% ggplot( aes(x=experiment, y=H2Omg, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") # ALL MALE DAYTIME PLOTS TOGETHER plot_grid(pEE, pRQ, pVO2, pVCO2, pH2O, labels = c('a) EE', 'b) RQ', 'c) VO2', 'd) VCO2', 'e) H2O (mg)'), label_size = 12) ### MALE NIGHT TIME VIOLIN PLOTS # EE pEE <- all_night_noOL_M %>% ggplot( aes(x=experiment, y=EE, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.title = element_text(size=14)) + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") pEE # RQ pRQ <- all_night_noOL_M %>% ggplot( aes(x=experiment, y=RQ, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + theme(legend.position="none") + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") # VO2 pVO2 <- all_night_noOL_M %>% ggplot( aes(x=experiment, y=VO2, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") #VCO2 pVCO2 <- all_night_noOL_M %>% ggplot( aes(x=experiment, y=VCO2, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") pVCO2 #H2Omg pH2O <- all_night_noOL_M %>% ggplot( aes(x=experiment, y=H2Omg, fill=experiment, color=experiment)) + geom_jitter(color = "darkgrey", alpha = 0.5, cex = 0.5) + geom_violin(width=1, size=0.5, alpha = 0.8) + scale_color_manual(values=c("grey31", "#0571B0", "#CA0020")) + scale_fill_manual(values=c("grey31", "#0571B0", "#CA0020")) + stat_summary(fun.data=mean_sdl, mult=1, geom="pointrange", color="black") + theme_ipsum() + theme(legend.position="none") + theme(plot.margin = unit(c(0.1,0.1,0.1,0.1), "lines")) + theme(plot.title = element_text(size=14)) + coord_flip() + # This switch X and Y axis and allows to get the horizontal version labs(title="", x = "", y ="") pH2O #MALE NIGHTTIME PLOTS TOGETHER plot_grid(pEE, pRQ, pVO2, pVCO2, pH2O, labels = c('a) EE', 'b) RQ', 'c) VO2', 'd) VCO2', 'e) H2O (mg)'), label_size = 12)