Colleagues ---------------------------------- System info: Version 1.3.0 (2001-06-22) on NT ESS v. 5.1.18 using emacs ver. 20.4 ---------------------------------- 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> x2INDICES: AGI [1] 0.729927 ------------------------------------------------------------ INDICES: BAR [1] NA ------------------------------------------------------------ INDICES: BYS [1] 85.71429 ------------------------------------------------------------ INDICES: CHA [1] 2.919708 ------------------------------------------------------------ INDICES: CIN [1] 36.31983 ------------------------------------------------------------ INDICES: CSU [1] 2381.685 ------------------------------------------------------------ INDICES: CYP [1] 1.260504 ------------------------------------------------------------ INDICES: ETB [1] 11.62791 ------------------------------------------------------------ INDICES: FRO [1] 0.7142857 ------------------------------------------------------------ INDICES: GSH [1] NA ------------------------------------------------------------ INDICES: HAK [1] 2.976854 ------------------------------------------------------------ INDICES: HJO [1] 85.78232 ------------------------------------------------------------ INDICES: HOK [1] 16.59766 ------------------------------------------------------------ INDICES: IDI [1] 4.379562 ------------------------------------------------------------ INDICES: JMM [1] 3.928571 ------------------------------------------------------------ INDICES: LAN [1] NA ------------------------------------------------------------ INDICES: LPA [1] 0.729927 ------------------------------------------------------------ INDICES: MAL [1] 0.729927 ------------------------------------------------------------ INDICES: MMU [1] NA ------------------------------------------------------------ INDICES: NOS [1] NA ------------------------------------------------------------ INDICES: ORH [1] 2.980198 ------------------------------------------------------------ INDICES: RBM [1] 17.08163 ------------------------------------------------------------ INDICES: RBT [1] 17.14286 ------------------------------------------------------------ INDICES: RBY [1] 0.7142857 ------------------------------------------------------------ INDICES: RCO [1] NA ------------------------------------------------------------ INDICES: RHY [1] 12.85714 ------------------------------------------------------------ INDICES: RIB [1] 0.729927 ------------------------------------------------------------ INDICES: SAW [1] 0.729927 ------------------------------------------------------------ INDICES: SCH [1] 0.3571429 ------------------------------------------------------------ INDICES: SDO [1] 399.7593 ------------------------------------------------------------ INDICES: SSI [1] 0.3571429 ------------------------------------------------------------ INDICES: SWA [1] 0.7142857 ------------------------------------------------------------ INDICES: TUB [1] 12.49747 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. Thanks Sam Sam McClatchie, Research scientist (fisheries acoustics)))))))))) NIWA (National Institute of Water & Atmospheric Research Ltd) PO Box 14 901, Kilbirnie, Wellington, New Zealand s.mcclatchie at niwa.cri.nz /\ ...>><xX(?> // \\ /// \\\ //// \\\\ /// <?)Xx><< ///// \\\\\\ ><(((?> >><(((?> ...>><xX(?>O<?)Xx><< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"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) > mybyINDICES: 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 thewizardry 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
It's nice to hear that this problem might be a bug, and that it can be fixed with ylim. I've been using the following function to get around it for barplots of matrices. So, for example, if m1 is a matrix, I say barplot(fill(m1)) fill <- function(x) {x[x=="NA"]<-0 ; return(x)} Jon Baron -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._