[R] barplot and NA
John D. Muccigrosso
internetj at muccigrosso.org
Mon Mar 12 17:57:52 CET 2012
On 12 Mar 2012, at 12:47 , S Ellison wrote:
> 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.
That makes sense, but since I do want a stacked bar plot, I'll need to change the NAs to 0 (which of course I've already done).
This should be made clear in the documentation, no? It's possible that barplot could do something like a na.rm=T internally and avoid this problem, but it doesn't, so NA is deadly in stacked plots. To be honest, if I hadn't scaled all my bars to 1 to show percentages, I wouldn't have noticed how some were leaving out a small category or two.
Thanks for the help.
More information about the R-help