[R] ylim problem in barplot

Martin Maechler maechler at stat.math.ethz.ch
Thu Jan 5 15:11:08 CET 2006


>>>>> "PaulB" == Bliese, Paul D LTC USAMH <paul.bliese at us.army.mil>
>>>>>     on Thu, 5 Jan 2006 14:01:17 +0100 writes:

    PaulB> R Version 2.2.0
    PaulB> Platform:  Windows

 
    PaulB> When I use barplot but select a ylim value greater
    PaulB> than zero, the graph is distorted.  The bars extend
    PaulB> below the bottom of the graph.

Well, my question would be if that is not a feature :-)
Many people would consider barplots that do not start at 0 as
 "Cheating with Graphics"  (in the vein of "Lying with Statistics").
 
    PaulB> For instance the command produces a problematic graph.

    PaulB> barplot(c(200,300,250,350),ylim=c(150,400))

The advantage of the current graphic drawn is that everyone *sees*
that the bars were cut off {and that one should really think
twice before producing such cheating graphics.. :-)}

 plot(c(200,300,250,350), ylim=c(150,400), type = "h", 
      lwd=20, xaxt="n", col="gray")

produces something closer to what you like.
[yes, you can get rid of the roundedness of the thick-line ends;
 --> ?par and look for 'lend';
 --> op <- par(lend = 1) ; plot(.........) ; par(op)
 In R-devel (i.e. from R 2.3.0 on) you can even say
  plot(c(200,300,250,350), ylim=c(150,400), type = "h", 
       lwd=20, xaxt="n", col="gray", lend = 1)
]

But after all, I tend to agree that R should behave a bit differently
here, 
e.g., first giving a warning about the non-approriate ylim 
but then still obey the ylim specification more nicely.  

Regards,
Martin Maechler




More information about the R-help mailing list