Re: [R] barplot and NA

2012-03-12 Thread John D. Muccigrosso
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.

John Muccigrosso

__
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] barplot and NA

2012-03-12 Thread S Ellison
 

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

__
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] barplot and NA

2012-03-12 Thread ilai
 d2 <- as.matrix(c(2,NA,4))
 barplot(d2,beside=T)
 barplot(c(d2))
 barplot(na.omit(d2))
 d2[2,] <- 0
 barplot(d2)

# So barplot is not "stopping" at the first NA (first 2 plots). But
what does stacking even mean when you have a missing group in the
middle ? you can't expect barplot to know... if you think it means 0
and the rest can just be stacked on top - define it that way.

Cheers

On Sun, Mar 11, 2012 at 10:22 PM, John D. Muccigrosso
 wrote:
> 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?
>
> Thanks.
>
> John
>
> __
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.