【问题标题】:Plotting barplot with bars by grouped/colored by group names通过按组名分组/着色的条形图绘制条形图
【发布时间】:2011-10-17 09:41:08
【问题描述】:

这个数据集是 CSV 格式的,

GO Biological Process,regulation of lipid metabolic process,1.87E-35
GO Biological Process,acute inflammatory response,3.21E-37
GO Biological Process,response to insulin stimulus,1.05E-38
GO Biological Process,steroid metabolic process,4.19E-39
GO Biological Process,cholesterol metabolic process,1.19E-40
GO Biological Process,cellular response to chemical stimulus,5.87E-42
GO Biological Process,alcohol metabolic process,5.27E-43
GO Biological Process,sterol metabolic process,2.61E-43
GO Biological Process,lipid homeostasis,1.12E-44
GO Biological Process,response to peptide hormone stimulus,1.29E-45
GO Biological Process,monocarboxylic acid metabolic process,2.33E-54
GO Biological Process,cellular ketone metabolic process,5.46E-74
GO Biological Process,carboxylic acid metabolic process,2.41E-76
GO Biological Process,organic acid metabolic process,5.30E-79
Pathway Commons,FOXA transcription factor networks,7.40E-61
Pathway Commons,FOXA2 and FOXA3 transcription factor networks,1.39E-64
Transcription Factor Targets,"Targets of HNF6, identified by ChIP-chip in hepatocytes",1.77E-32
Transcription Factor Targets,"Targets of HNF1alpha, identified by ChIP-chip in hepatocytes",3.87E-65
Transcription Factor Targets,"Targets of HNF4alpha, identified by ChIP-chip in hepatocytes",1.38E-131

我希望能够创建一个如下所示的图(条形图?):

第 1 列中的三个不同组以相同的颜色分组在一起,第 3 列从大到小排序。 上面的图是用 excel 制作的,但我希望能够在 R 中正确制作。 到目前为止,我得到的只是绘制的第二列和第三列,我无法得到按第一列分组的条形图。


嗯,我已经按照建议尝试了 ggplot。这就是我得到的(顺便说一句,它看起来很棒):

library(ggplot2)
ggplot(tmp, aes(x=tmp$V2, y=log(tmp$V3), fill=tmp$V1)) +
geom_bar(stat="identity") +
coord_flip() +
scale_y_log()

但是,我需要了解如何“反转”轴,例如 [0, 1e-130](例如,条形图从左到右,就像我上面的示例一样)

【问题讨论】:

    标签: r plot colors histogram


    【解决方案1】:

    这在ggplot2 包中使用ggplot 相当简单。您可以通过在绘图中指定填充颜色并将数据中的列映射到填充来实现此目的,即aes(..., fill=group)

    library(ggplot2)
    dat <- data.frame(
        label=LETTERS[1:10],
        value=10:1,
        group=letters[c(1,1,2,2,2,3,3,3,3,3)]
    )
    
    dat
       label value group
    1      A    10     a
    2      B     9     a
    3      C     8     b
    4      D     7     b
    5      E     6     b
    6      F     5     c
    7      G     4     c
    8      H     3     c
    9      I     2     c
    10     J     1     c
    
    ggplot(dat, aes(x=label, y=value, fill=group)) + 
        geom_bar(stat="identity") +
        coord_flip()
    

    【讨论】:

    • 看起来真不错。我对 ggplot 完全不熟悉,但我会尝试一下 - 感谢您的快速回复!
    • 上帝,ggplot 是一个全新的世界!非常有趣,但似乎要复杂得多......
    猜你喜欢
    • 1970-01-01
    • 2020-05-15
    • 2018-01-06
    • 2021-11-25
    • 1970-01-01
    • 2012-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多