【问题标题】:R multiple-column horizontal barplotR多列水平条形图
【发布时间】:2018-07-17 15:17:56
【问题描述】:

我正在寻求有关水平条形图和两列的帮助。

例如这段代码:

set.seed(112)
data <- t(matrix(sample(1:30,8) , nrow=))
colnames(data) <- c("H","G","F","E","D", "C", "B", "A")

barplot(data, border="white", space=0.04, font.axis=2,
        main = "Barplot",
        horiz = TRUE, las = 1)

生成此条形图:

我正在寻找可以让我得到类似这样的代码(注意固定比例):

动机:我想要一个带有水平文本的条形图(更容易阅读),但是通过更多的观察,这会产生非常高的图像。将绘图拆分为两列将允许在宽图像上显示水平文本。

感谢任何提示!

【问题讨论】:

    标签: r plot bar-chart multiple-columns


    【解决方案1】:
    set.seed(112)
    data <- t(matrix(sample(1:30,8) , nrow=))
    colnames(data) <- c("H","G","F","E","D", "C", "B", "A")
    
    par(mfrow = c(1,2)) #to plot on 1 row in 2 columns
    barplot(data[,5:8, drop = F], border="white", space=0.04, font.axis=2, #subset data, and drop  = F to prevent your matrix from losing a dimension, i.e. getting converted to a vector
            main = "Barplot",
            horiz = TRUE, las = 1, xlim = c(0,25)) #set the xlimits
    
    barplot(data[,1:4, drop = F], border="white", space=0.04, font.axis=2,
            main = "Barplot",
            horiz = TRUE, las = 1, xlim = c(0,25)) # set the same xlimits
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-04
      • 2013-11-22
      • 1970-01-01
      • 2023-03-29
      • 2017-09-30
      相关资源
      最近更新 更多