# [R] Y-limits of barplots

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Mar 25 14:21:14 CET 1999

```"Uli Flenker; Raum 704" <uli at biochem.dshs-koeln.de> writes:

> I frequently have to produce barplots from variables the natural variation
> of which is far away from zero. A typical range would be, say from -16 to
> -28.
>
> So, the following example should give an "honest" presentation:
>
> x<-c(-20,-22,-21,-28)
> barplot(x,beside=T,ylim=c(-18,-30))
>
> But using anything else but "0" for the first element of ylim
> leads to strange results, as the bars "ignore" the X-axis and keep on
> extending to zero. (R 0.63.2, Linux 2.0.25)
>
> Any idea how to avoid this behaviour (without doing a rewrite of
> "barplot")?

I suppose some would say you deserve what you get and that it doesn't
really make sense to describe such data with barplots...

However, if you insist, try something like:

x<-c(-20,-22,-21,-28)
names(x)<-c("eenie","meenie","miney","moe")
barplot(-x-18,beside=T,ylim=c(0,12),axes=F)
axis(2,at=seq(0,12,2),labels=seq(-18,-30,-2))

--
O__  ---- Peter Dalgaard             Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics     2200 Cph. N
(*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```