If I want to flip the histogram how would I do it. I tried google but couldn't find anything useful. Please help.
Asked
Active
Viewed 7,206 times
-2
-
4Could you provide us with a reproducible example. If you use `ggplot2`, you can use `coord_flip()` to do this. – Paul Hiemstra Apr 04 '17 at 16:35
-
Possible duplicate of [Vertical Histogram](http://stackoverflow.com/questions/13327489/vertical-histogram) – David Heckmann Apr 04 '17 at 16:36
-
1Are you sure you googled it right? Look at here: http://www.sthda.com/english/wiki/ggplot2-rotate-a-graph-reverse-and-flip-the-plot – M-- Apr 04 '17 at 16:37
1 Answers
2
What you likely want is a barplot, as histogram cannot be flipped. See following for example of barplots:
http://www.statmethods.net/graphs/bar.html
Note last plot "flips" axis as you require:
par(las=2) # make label text perpendicular to axis
par(mar=c(5,8,4,2)) # increase y-axis margin.
counts <- table(mtcars$gear)
barplot(counts, main="Car Distribution", horiz=TRUE, names.arg=c("3 Gears", "4 Gears", "5 Gears"), cex.names=0.8)
It uses the horiz=TRUE
option to flip the axes.
To convert a histogram to barplot, do something similar to:
h <- hist(rnorm(1000))
barplot(h$counts, horiz = TRUE)

Vince
- 3,325
- 2
- 23
- 41