R语言R语言可视化

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

2019-03-11  本文已影响10人  热衷组培的二货潜
> 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

上一篇下一篇

猜你喜欢

热点阅读