[R] Histograms rotated, side-by-side

Renaud Lancelot lancelot at sentoo.sn
Mon May 13 11:58:47 CEST 2002


An alternative solution is to use barchart (after transformation of the
data to get groups and sizes or means). This will ensure that plots are
on the same scale:

library(lattice)
data(barley)
barchart(variety ~ yield | year * site,
          data = barley, horizontal = T,
          ylab = "Barley Yield (bushels/acre)",
          scales = list(x = list(0, abbreviate = TRUE, minlength = 5)))

Best,

Renaud

Ott Toomet wrote:
> 
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-- 
Dr Renaud Lancelot, vétérinaire
CIRAD, Département Elevage et Médecine Vétérinaire (CIRAD-Emvt)
Programme Productions Animales
http://www.cirad.fr/presentation/programmes/prod-ani.shtml (Français)
http://www.cirad.fr/presentation/en/program-eng/prod-ani.shtml (English)

ISRA-LNERV                      tel    (221) 832 49 02
BP 2057 Dakar-Hann              fax    (221) 821 18 79 (CIRAD)
Senegal                         e-mail renaud.lancelot at cirad.fr
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list