[R] barplot and NA
S Ellison
S.Ellison at LGCGroup.com
Mon Mar 12 17:47:54 CET 2012
> -----Original Message-----
> Am I wrong that barplot is supposed to just skip NAs, and
> continue with the rest of the data in a matrix column? That's
> how I read various posts on the subject.
>
> But that's not what happens for me with R64.app (on a Mac,
> obviously). For example:
>
> d0 <- as.matrix(c(2,3,4))
> d1 <- as.matrix(c(2,3,NA))
> d2 <- as.matrix(c(2,NA,4))
> d3 <- as.matrix(c(NA,3,4))
> barplot(d0)
> barplot(d1)
> barplot(d2)
> barplot(d3)
>
> generates four bar plots. The first has one bar with three
> visible bands, as expected. The second has two bands; still
> OK. But the third has only one band (at 2) and the fourth has none.
>
> So it appears that barplot is barfing on those NAs and
> stopping its plot at those points.
>
> Is that the expected behavior?
Yes, to the extent that the default barplot plots the height of the bar so far as the sum of teh values so far, starting at teh first. For your first vector, no problem; for your second, the highest value is undefiuned, for the third, the sum is undefined after the second value (an NA) and so on.
Try adding 'beside=TRUE to the barplots, as in
barplot(d3, beside=TRUE)
and you will see all the known values plotted as you;d expect.
Steve E*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}
More information about the R-help
mailing list