# [R] Histograms rotated, side-by-side

Ott Toomet siim at obs.ee
Mon May 13 11:18:07 CEST 2002

```On Mon, 13 May 2002, Rachel Cunliffe wrote:

|Hi there,
|
|I am wanting to create 8 side-by-side histograms which have been rotated 90
|degrees clockwise from how they usually sit.. all with the same scales.  Is
|someone able to help me out?

I do not know any histogram function which can display horizontal histogram.
You have to do a workaround using barplot(horis=TRUE).  E.g. define a
function like this:

horiz.hist <- function(x) {
a <- hist(x, plot=FALSE)
barplot(a\$density, space=0, horiz=TRUE)
width <- a\$breaks[2] - a\$breaks[1]
axis(2, at=(pretty(a\$breaks) - a\$breaks[1])/width,
labels=pretty(a\$breaks))
}

And now you can say

> par(mfrow=c(1,8))
> for(i in 1:8) horiz.hist(rnorm(100))

It works for me.  You may consider playing further to get equal scale for
all the histograms.

Cheers,

Ott

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```