【问题标题】:R script plot with ID on xaxis and all column values on yaxisR 脚本在 x 轴上绘制 ID,在 y 轴上绘制所有列值
【发布时间】:2016-08-25 07:44:20
【问题描述】:

我是 R 脚本的新手,需要帮助绘制数据。 我的数据是这样的

  run1Seek run2Seek run3Seek
1       12       23       28
2       10       27        0
3       23       19        0
4       22       24        0
5       21       26        0
6       11       26        0

我需要在 x 轴上绘制 ID 值,在 y 轴上绘制 run1Seek、run2Seek、run3Seek 值。下图是这样的:

【问题讨论】:

    标签: r ggplot2 rscript


    【解决方案1】:

    试试这个:

    library(ggplot2)
    
    # Random data
    mat <- matrix(sample(1:100, size = 1000, replace = T), ncol = 2)
    colnames(mat) <- c("Run1Seek", "Run2Seek")
    
    # Make data frame
    ds <- data.frame(ID = 1:500, mat)
    
    # Melt to long format
    ds <- reshape2::melt(ds, "ID")
    
    # Look at data
    head(ds)
    
    # Plot
    ggplot(ds, aes(x = ID, y = value, fill = variable)) + geom_bar(stat = "identity")
    

    【讨论】: