R语言_绘制boxplot图

如题所述

再写一篇。

加载数据

rm(list = ls())

data <- read.delim("gene conc.txt")

library(ggplot2)

library(ggpubr)

df <- data[which(data$Gene == "ADAM*"),]

df$Time = factor(df$Time, levels = c("Control", "Before thrombolytic therapy", "After thrombolytic therapy"))

head(df, 4)

##1. boxplot图

绘制带有抖动点的箱线图

使用自定义色彩方案

添加抖动点和根据时间改变形状

p <- ggboxplot(df, x = "Time", y = "Conc",

color = "Time", palette = c("#00AFBB", "#E7B800", "#FC4E07"),

add = "jitter", shape = "Time")

p

添加比较组的p值

指定要比较的内容

my_comparisons <- list(c("Before thrombolytic therapy", "Control"), c("After thrombolytic therapy", "Before thrombolytic therapy"), c("After thrombolytic therapy", "Control"))

p + stat_compare_means(comparisons = my_comparisons, method = "wilcox.test") + # 添加成对比较的p值

stat_compare_means(label.y = 50) # 添加全局p值

p + stat_compare_means(comparisons = my_comparisons, method = "wilcox.test") + # 添加成对比较的p值

stat_compare_means(comparisons = my_comparisons, method = "wilcox.test", label = "p.signif")

##2.小提琴图

绘制包含箱线图的小提琴图

改变填充颜色以分组:剂量

添加白色填充颜色的箱线图

ggviolin(df, x = "Time", y = "Conc", fill = "Time",

palette = c("#00AFBB", "#E7B800", "#FC4E07"),

add = "boxplot", add.params = list(fill = "white"))+

stat_compare_means(comparisons = my_comparisons, method = "wilcox.test", label = "p.signif") + # 添加显著性水平

stat_compare_means(label.y = 50) # 添加全局p值

ggviolin(df, x = "Time", y = "Conc", fill = "Time",

palette = c("#00AFBB", "#E7B800", "#FC4E07"),

add = "boxplot", add.params = list(fill = "white"))+

stat_compare_means(comparisons = my_comparisons, method = "wilcox.test", label = "p.signif") # 添加显著性水平
温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜