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.
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")
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With