Reputation: 333
Can anyone help me how to rotate histogram just by 90 degrees in r? I know there is an option (horiz=T) in boxplot but I have no idea if there is a similar one for the histogram.
Upvotes: 8
Views: 8561
Reputation: 9495
If you use ggplot2
, you can use 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()
Upvotes: 1
Reputation: 11128
I think you have to use hist with barplot to do it like below (its straight from documentation), you can check it here ?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")
Upvotes: 5