[R] by/ NA/ barplot

Prof Brian D Ripley ripley at stats.ox.ac.uk
Wed Jul 4 08:40:22 CEST 2001


On Wed, 4 Jul 2001, S.McClatchie wrote:

> I have generated an object (class = by) with NA values and want to plot
> the output as a bargraph:
>
>   x2 <- by(scl.nos, species, sum)
>
> These data are summed counts of fish by species

[...]

> When I try to plot them I get an error due to the NA values, I think:
>
> >  barplot(x2,
> +             xlab='fish length (SL or TL)  cm',
> +             ylab='individuals per nm towed', col='black')
> Error in plot.window(xlim, ylim, log, asp, ...) :
> 	need finite ylim values
>
> Plot.table gives me the same error and I tried na.rm=TRUE to no effect.
> Is this simple to solve? I guess I need to replace the NAs with zeros in
> one of the by attributes?

barplot does not accept NAs.  That's a bug, I believe.  It will work if you
specify ylim, as in (modifying the first exammple)

tN <- table(Ni <- rpois(100, lambda=5))
tN[3] <- NA
r <- barplot(tN, col='gray')
Error in plot.window(xlim, ylim, log, asp, ...) :
        need finite ylim values

r <- barplot(tN, col='gray', ylim=c(0,25)) # works.

I assume you want the bar omitted in the NA cases.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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