配对箱线图,常见于配对样本的数据分析中。
这种配对箱线图的好处是,除了能够表现两组的整体差异,还能够清晰地呈现单个样本的前后改变。
数据结构:
输入数据格式代码部分:
library(ggplot2)
library(forcats)
library(ggpubr)
ggplot(df, aes(x =group , y = LAI)) +
geom_boxplot(aes(fill = group), show.legend = F, width = 0.6) + #箱线图
scale_fill_manual(values = c('#00AFBB', '#E7B800')) + #设置颜色
geom_point(size = 3,color='red') +
geom_point(size = 3,shape=21) + #绘制散点
geom_line(aes(group = saple), color = 'gray', lwd = 0.5) + #配对样本间连线
theme(panel.grid = element_blank(),
axis.line = element_line(colour = 'black', size = 1),
panel.background = element_blank(),
plot.title = element_text(size = 15, hjust = 0.5),
plot.subtitle = element_text(size = 15, hjust = 0.5),
axis.text = element_text(size = 15, color = 'black'),
axis.title = element_text(size = 15, color = 'black')) +
labs(x = 'Strategy', y = 'LAI', title = 'A vs B')+
stat_compare_means(method = "t.test",paired = TRUE, comparisons=list(c("A", "B")))#配对t检验
结果图
网友评论