加载数据分析包
library(sysfonts) #显示中文
library(showtext) #显示中文
showtext.auto(enable=T) #显示中文
font.add('SimSun','华文仿宋.ttf')
library(ggsci) #sci配色
library(reshape2) #融合数据
library(ggplot2) #绘图工具
library(openxlsx)
library(ggpubr) #ggplot优化工具
library(dplyr) #数据整理工具
加载数据
柱形图 <- file.choose() #选择数据
databar <- read.csv(柱形图,header = T,stringsAsFactors = F,check.names = F) #加载数据
databar <- na.omit(databar) #删除缺失值
f1<-databar %>% #选择数据
group_by(提取溶剂)%>% #通过提取溶剂整理数据
summarize(
mean_score = mean(总黄酮含量),
se = sqrt(var(总黄酮含量)/length(总黄酮含量)),
.groups = "drop"
) %>% #整理数据
mutate(
lower = mean_score -se,
upper = mean_score +se
) #添加数据
整理数据
f1<-f1[c(1,8,5,11,3,4,6,7,9,10,2),] #通过第一列整理数据
判断组间显著性
compare_means(mean_score ~ 提取溶剂, data = f1) #查看独立双样本之间显著性关系
my_comparisons <- list( c("100%甲醇","70%乙醇")) #输入想要比较显著性的组
画图
ggplot(f1,mapping=aes(x=提取溶剂,y=mean_score,fill=提取溶剂,group=1))+
geom_bar(stat = "identity",width=0.8,show.legend = F,color="black")+
labs(x="提取溶剂",y="总黄酮含量",title="总黄酮提取溶剂筛选")+
geom_errorbar(aes(x=提取溶剂,y =mean_score,ymin=lower,ymax=upper),data = f1,width=0.4)+
scale_x_discrete(limits=factor(f1$提取溶剂))
+scale_y_continuous(expand=c(0,0),limits = c(0,0.088),labels = scales::percent)+
geom_point(pch=21,aes(fill=提取溶剂),color="black",color="skyblue",size=2,show.legend = F)+
geom_line(aes(color=提取溶剂),linetype="dashed",color="black",size=1)+
theme_bw()
+
theme(axis.title.x = element_text(face = "bold",size = 16,colour = "black"),
axis.title.y = element_text(face = "bold",size = 16,colour = "black"),
axis.text.x = element_text(size = 12,colour = "black"),
axis.text.y = element_text(size =12,colour = "black"),
plot.title = element_text(face = "bold",size =16,colour = "black",hjust = 0.5),
panel.background = element_rect(colour = "black",size = 1.2))+
geom_text(aes(label=c("7.2%","6.7%","6.4%","3.6%","5.3%","6.1%","6.3%","6.9%","7%","6.4%","5%"),y=upper+0.003,color=提取溶剂),show.legend = F)+
scale_fill_npg()+
scale_color_npg()
+
stat_compare_means(comparisons = my_comparisons,label = "p.signif",label.y = 0.08)