Box plots (箱体图)
library(ggpubr)
data("ToothGrowth")
df<-ToothGrowth
p <- ggboxplot(df, x = "dose", y = "len",color = "dose", palette =c("#00AFBB", "#E7B800", "#FC4E07"),add = "jitter", shape = "dose")
p
![](https://img.haomeiwen.com/i19696329/b4a4befcce5bc9c0.png)
# Add p-values comparing groups
# Specify the comparisons you want
my_comparisons <- list( c("0.5", "1"), c("1", "2"), c("0.5", "2") )
p1<-p + stat_compare_means(comparisons = my_comparisons) # Add pairwise comparisons p-value
+stat_compare_means(label.y = 50) # Add global p-value
p1
![](https://img.haomeiwen.com/i19696329/ca83d8da030d2a9c.png)
Violin plot with boxplot (小提琴图)
# Change fill color by groups: dose
# add boxplot with white fill color
# Violin plots with box plots inside
# :::::::::::::::::::::::::::::::::::::::::::::::::::
# Change fill color by groups: dose
# add boxplot with white fill color
p2<-ggviolin(df, x = "dose", y = "len", fill = "dose",palette = c("#00AFBB", "#E7B800", "#FC4E07"),add = "boxplot", add.params = list(fill = "white"))+
stat_compare_means(comparisons = my_comparisons, label = "p.signif")+ # Add significance levels
stat_compare_means(label.y = 50) # Add global the p-value
p2
![](https://img.haomeiwen.com/i19696329/b3fe8fe30495e0c7.png)
Density plot (密度图)
set.seed(1234)
wdata = data.frame(
sex = factor(rep(c("F", "M"), each=200)),
weight = c(rnorm(200, 55), rnorm(200, 58)))
head(wdata, 4)
#> sex weight
#> 1 F 53.79293
#> 2 F 55.27743
#> 3 F 56.08444
#> 4 F 52.65430
# Change outline and fill colors by groups ("sex")
# Use custom palette
p3<-ggdensity(wdata, x = "weight",add = "mean", rug = TRUE,color = "sex", fill = "sex",palette = c("#00AFBB", "#E7B800"))
![](https://img.haomeiwen.com/i19696329/5d55d0a74b7a6438.png)
Histogram plot (直方图)
# Histogram plot with mean lines and marginal rug
# Change outline and fill colors by groups ("sex")
# Use custom color palette
p4<-gghistogram(wdata, x = "weight", add = "mean", rug = TRUE,color = "sex", fill = "sex",palette = c("#00AFBB", "#E7B800"))
p4
![](https://img.haomeiwen.com/i19696329/771271281961baef.png)
以上图片,可以通过patchwork包将其进行排版组合
Example
library(patchwork)
plot<-p+p1+p3
plot
![](https://img.haomeiwen.com/i19696329/5b61d96a64ebffb7.png)
plot1<-p3/p4
plot1
![](https://img.haomeiwen.com/i19696329/7dbc0bdcba415a0d.png)
plot2<-p / p1 | p4
plot2
![](https://img.haomeiwen.com/i19696329/5690d09961098d1a.png)
网友评论