【问题标题】:Rotating histogram horizontally in r在r中水平旋转直方图
【发布时间】:2018-06-12 06:04:28
【问题描述】:

谁能帮助我如何将直方图在 r 中旋转 90 度?我知道箱线图中有一个选项(horiz=T),但我不知道直方图是否有类似的选项。

【问题讨论】:

    标签: r plot histogram


    【解决方案1】:

    我认为您必须像下面那样使用 hist 和 barplot(直接来自文档),您可以在此处查看 ?layout。

    x <- pmin(3, pmax(-3, stats::rnorm(50)))
    xhist <- hist(x, breaks = seq(-3,3,0.5), plot = FALSE)
    barplot(xhist$counts, axes = TRUE, space = 0, horiz=TRUE, xlab= "Counts", ylab="Bins")
    

    【讨论】:

    • 感谢@PKumar 的回复。我的数据框在 -16.18 和 1019.93 的范围内,中位数为 0.03。当我尝试更改 ylim (在 -1 和 1 的范围内)时,它给了我一条线。知道如何调整 y 限制吗?
    • @SoheilKoushan,将您的数据的样本随机记录与您的问题放在一起是个好主意。
    【解决方案2】:

    如果你使用ggplot2,你可以使用coord_flip()

        # here with @PKumar data
        x <- pmin(3, pmax(-3, stats::rnorm(50)))
        library(ggplot2)
        qplot(x, geom="histogram",binwidth = 0.3) + coord_flip()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-24
      • 1970-01-01
      • 2018-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-06
      • 1970-01-01
      相关资源
      最近更新 更多