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.
Asked
Active
Viewed 7,082 times
2 Answers
5
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")

PKumar
- 10,971
- 6
- 37
- 52
-
Thanks for the reply @PKumar. My data frame is in the range of -16.18 and 1019.93 with a median of 0.03. When I try to change the ylim (something in the range of -1 and 1), it gives me a line. Any idea how to adjust the y limit? – Soheil Jun 12 '18 at 06:25
-
2@SoheilKoushan, Its a good idea to put sample random records of your data with your question. – PKumar Jun 12 '18 at 06:39
1
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()

s__
- 9,270
- 3
- 27
- 45