画组间比较图形一般选择条形图,而我们会选择组间均值展示组间条形图。更多知识分享请到 https://zouhua.top/。
library(dplyr)
library(tibble)
library(data.table)
library(ggplot2)
library(xlsx)
load data
phen <- read.xlsx("miRNA_20210129.xlsx", sheetIndex = 1)
prof <- fread("miRNA_count_profile.tsv")
miRNA_name <- "mmu-miR"
HF
- Rmisc包的summarySE函数可计算所需要的平均值和标准误差等描述性统计变量。
dat <- prof %>% filter(miRNA==miRNA_name) %>%
dplyr::select(-precursor) %>%
column_to_rownames("miRNA") %>%
t() %>% data.frame() %>%
rownames_to_column("SampleID") %>%
inner_join(subset(phen, select=c(SampleID, Group)), by="SampleID") %>%
filter(Group%in%c("HF", "HF_NC")) %>%
mutate(Group=factor(Group, levels = c("HF", "HF_NC")))
dat_se <- Rmisc::summarySE(data = dat, measurevar = "mmu.miR", groupvars = "Group")
# pval <- wilcox.test(mmu.miR ~ Group, data = dat)$p.value
pl <- ggplot(dat_se, aes(x=Group, weight=mmu.miR, fill=Group))+
geom_hline(yintercept = seq(0, 8000, 2000), color = 'gray')+
geom_bar(color = "black", width = .4, position = 'dodge') +
geom_errorbar(aes(ymin = mmu.miR - se, ymax = mmu.miR + se),
width = 0.25, size = 0.3, position = position_dodge(0.7))+
labs(x="", y="the Counts of mmu-miR-5099")+
scale_fill_brewer(palette = "Set3")+
scale_y_continuous(expand = c(0, 0), limits = c(0, 8500))+
annotate("segment", x=1, xend=2, y=7700, yend = 7700, color = "black", size=1)+
annotate("text", x=1.5, y=8000, label=paste0("p=",
round(wilcox.test(mmu.miR ~ Group, data = dat)$p.value, 3)))+
theme_classic()+
guides(fill=F)+
theme(axis.title = element_text(face = 'bold',color = 'black',size = 14),
axis.text = element_text(color = 'black',size = 10),
text = element_text(size = 8, color = "black", family="serif"),
legend.position = 'right',
legend.key.height = unit(0.6,'cm'),
legend.text = element_text(face = "bold", color = 'black',size = 10),
strip.text = element_text(face = "bold", size = 14))
pl

参考
参考文章如引起任何侵权问题,可以与我联系,谢谢。
网友评论