在r中水平旋转直方图

Soh*_*eil 7 plot r histogram

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

PKu*_*mar 5

我认为你必须使用 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")
Run Code Online (Sandbox Code Playgroud)

  • @SoheilKoushan,将数据的样本随机记录与您的问题放在一起是个好主意。 (2认同)

s_t*_*s_t 1

如果您使用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()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述