Skip to content
Back to formatted view

Raw Message

Message-ID: <2gpv70ls15pc2vgp24rulc5he7hod1a6gj@4ax.com>
Date: 2004-04-16T15:59:02Z
From: Duncan Murdoch
Subject: barplot() does not draw bars correctly in R 1.9.0 (PR#6776)
In-Reply-To: <20040416154452.7af33944.Achim.Zeileis@wu-wien.ac.at>

On Fri, 16 Apr 2004 15:44:52 +0200, Achim Zeileis
<Achim.Zeileis@wu-wien.ac.at> wrote :

>On Fri, 16 Apr 2004 11:40:46 +0200 (CEST) phgrosjean@sciviews.org wrote:
>
>> Bars are not stacked, but superimposed. This happens even with the
>> first example of barplot:
>> 
>>      tN <- table(Ni <- rpois(100, lambda=5))
>>      r <- barplot(tN, col='gray')
>
>AFAICS, this problem occurs exactly for 1-way tables like above. If
>
>barplot(as.vector(tN), col = "gray")
>
>is used instead, everything is as it was in 1.8.1. The reason is that in
>the new version of barplot.default the following code (which
>remained unchanged) does not do anymore what do what one would want:
>
>    if (is.vector(height)) {
>        height <- cbind(height)
>        beside <- TRUE
>    }
>    else if (is.array(height) && (length(dim(height)) == 1)) {
>        height <- rbind(height)
>        beside <- TRUE
>    }
>
>that is, vectors and 1-way tables are treated differently which lead to
>the problem. Using cbind() instead of rbind() in the second half,
>overcomes this problem.
>However, the colors are then chosen in the same way as for vectors,
>resulting in different colors than in R 1.8.1. Maybe the default color
>choice should then be modified as well.

I'm pretty sure the problem is due to this change, a few lines below
the ones you listed:

1.8.1:       width <- rep(width, length.out = NR * NC)

1.9.0:       width <- rep(width, length.out = NR)

This change was made at the same time as the offset arg was
introduced; is it intentional?

Duncan Murdoch