library(tidyverse)#> Warning: package 'purrr' was built under R version 4.5.2#> Warning: package 'stringr' was built under R version 4.5.2#> Warning: package 'forcats' was built under R version 4.5.2#> ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──#> ✔ dplyr 1.1.4 ✔ readr 2.1.6#> ✔ forcats 1.0.1 ✔ stringr 1.6.0#> ✔ ggplot2 4.0.1 ✔ tibble 3.3.0#> ✔ lubridate 1.9.4 ✔ tidyr 1.3.1#> ✔ purrr 1.2.0 #> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──#> ✖ dplyr::filter() masks stats::filter()#> ✖ dplyr::lag() masks stats::lag()#> ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errorslibrary(ggprism)#> Warning: package 'ggprism' was built under R version 4.5.2df_p_val<-rstatix::t_test(ToothGrowth, len~dose, ref.group ="0.5")%>%rstatix::add_xy_position()p<-ggplot(ToothGrowth, aes(x =factor(dose), y =len))+stat_summary(geom ="col", fun =mean)+stat_summary(geom ="errorbar", fun =mean, fun.min =function(x)mean(x)-sd(x), fun.max =function(x)mean(x)+sd(x), width =0.3)+theme_prism()+coord_cartesian(ylim =c(0, 40))+scale_y_continuous(breaks =seq(0, 40, 5), expand =c(0, 0))# with bracketsp1<-p+add_pvalue(df_p_val, label ="p.adj.signif",label.size =8)# without bracketsp2<-p+add_pvalue(df_p_val, label ="p.adj.signif", remove.bracket =TRUE,label.size =8)library(patchwork)#> Warning: package 'patchwork' was built under R version 4.5.2p1+p2
library(ggpubr)#> Warning: package 'ggpubr' was built under R version 4.5.2data("ToothGrowth")df<-ToothGrowthp<-ggboxplot(data =df, x ="dose", y ="len", color ="dose", palette ="gsea", add ="jitter", shape ="dose", bxp.errorbar =TRUE, bxp.errorbar.width =0.1,)p
ggviolin(data =df, x ="dose", y ="len", fill ="dose", palette ="gsea", add ="boxplot", add.params =list(fill="white"),)+stat_compare_means(comparisons =my_compare, label ="p.signif", method ="t.test")+stat_compare_means(label.y =50)# 总体p值
1.2.3 ggbarplot
Code
ggbarplot( data =df, x ="dose", y ="len", fill ="supp", color ="black", palette ="lancet", add =c("mean_se"),# mean_sd, mean_ci error.plot ="errorbar",# upper_errorbar,"lower_errorbar",pointrange,"linerange", "crossbar", label =TRUE, lab.pos ="in", position =position_dodge(), orientation ="vertical", order =c("0.5", "2", "1"),)