使用R中ggplot2和Hmisc绘制带误差线的柱状图

> BiocManager::install("Biobase", version = "3.8")
> library("Hiiragi2013")
> data("x")
> dim(Biobase::exprs(x))

> selectedProbes = c( Fgf4 = "1420085_at", Gata4 = "1418863_at",
+                    Gata6 = "1425463_at",  Sox2 = "1416967_at")

> library("reshape2")
> genes = melt(Biobase::exprs(x)[selectedProbes, ],
+              varnames = c("probe", "sample"))
> head(genes)
       probe  sample    value
1 1420085_at 1 E3.25 3.027715
2 1418863_at 1 E3.25 4.843137
3 1425463_at 1 E3.25 5.500618
4 1416967_at 1 E3.25 1.731217
5 1420085_at 2 E3.25 9.293016
6 1418863_at 2 E3.25 5.530016

> genes$gene =
  names(selectedProbes)[match(genes$probe, selectedProbes)]
> head(genes)
       probe  sample    value  gene
1 1420085_at 1 E3.25 3.027715  Fgf4
2 1418863_at 1 E3.25 4.843137 Gata4
3 1425463_at 1 E3.25 5.500618 Gata6
4 1416967_at 1 E3.25 1.731217  Sox2
5 1420085_at 2 E3.25 9.293016  Fgf4
6 1418863_at 2 E3.25 5.530016 Gata4

> library("Hmisc")
> ggplot(genes, aes( x = gene, y = value, fill = gene)) +
+   stat_summary(fun.y = mean, geom = "bar") +
+   stat_summary(fun.data = mean_cl_normal, geom = "errorbar",
+                width = 0.25)
image.png

参考来源 3.6.1 Barplots

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容