[R] by/ NA/ barplot

Laurent Gautier laurent at cbs.dtu.dk
Wed Jul 4 10:06:14 CEST 2001


"S.McClatchie" wrote:

> Colleagues
>
> (...)
>
> 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?
>
> Help will be appreciated.





I guess it depends on what how you want to consider the NAs.


One way is just to ignore these unspecified values in the plot.


>data(warpbreaks)
>attach(warpbreaks)
>warpbreaks$breaks[which(warpbreaks$tension == "L")]  <-  NA
> myby <- by(warpbreaks$breaks,tension,sum)
> myby
INDICES: L
[1] NA
------------------------------------------------------------
INDICES: M
[1] 475
------------------------------------------------------------
INDICES: H
[1] 390
> #there must be a more elegant way, so I am looking forward to seeing the
wizardry suggested by a
> #member of the R core development team
>barplot(myby[- which(is.na(myby))])


Cheers,




Laurent



>

--
Laurent Gautier                 CBS, Building 208, DTU
PhD. Student                    D-2800 Lyngby,Denmark
tel: +45 45 25 24 85            http://www.cbs.dtu.dk/laurent


-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://stat.ethz.ch/pipermail/r-help/attachments/20010704/f52d77a1/attachment.html


More information about the R-help mailing list