- 数据类型
- R语言绘图代码
# 一次性加载所有需要的包
library(ggplot2)
library(dplyr)
library(tidyr)
# 导入数据
df_wide <- read.delim("E:/Retrogene课题/小孢子叶球注射过表达基因结果/小孢子叶球定量实验/5876.txt", stringsAsFactors = FALSE)
# 宽转长格式(等价于 melt)
df_long <- pivot_longer(df_wide, cols = everything(),
names_to = "Group", values_to = "Expression")
# 计算统计量
df_summary <- df_long %>%
group_by(Group) %>%
summarise(
Mean = mean(Expression),
SE = sd(Expression) / sqrt(n()),
.groups = 'drop'
)
# 画图
ggplot(df_summary, aes(x = Group, y = Mean, fill = Group)) +
geom_col(width = 0.6, color = "black") +
geom_errorbar(aes(ymin = Mean - SE, ymax = Mean + SE), width = 0.2) +
geom_text(aes(label = round(Mean, 2)), vjust = -0.5) +
scale_fill_manual(values = c("X5876_CK" = "#A1CAF1", "X5876_OE" = "#FFD3C4")) +
theme_minimal(base_size = 14) +
labs(x = NULL, y = "Expression (Mean ± SE)", fill = NULL) +
theme(legend.position = "none")
- 结果
原文链接:R语言绘制柱状图