Skip to content

barplot() does not draw bars correctly in R 1.9.0 (PR#6776)

5 messages · Philippe GROSJEAN, Duncan Murdoch, Achim Zeileis +1 more

#
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')

--please do not edit the information below--

Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status =
 major = 1
 minor = 9.0
 year = 2004
 month = 04
 day = 12
 language = R

Windows XP Professional (build 2600) Service Pack 1.0

Search Path:
 .GlobalEnv, package:methods, package:stats, package:graphics,
package:utils, Autoloads, package:base

.......................................................<?}))><....
 ) ) ) ) )
( ( ( ( (   Prof. Philippe Grosjean
\  ___   )
 \/ECO\ (   Numerical Ecology of Aquatic Systems
 /\___/  )  Mons-Hainaut University, Pentagone
/ ___  /(   8, Av. du Champ de Mars, 7000 Mons, Belgium
 /NUM\/  )
 \___/\ (   phone: + 32.65.37.34.97, fax: + 32.65.37.33.12
       \ )  email: Philippe.Grosjean@umh.ac.be
 ) ) ) ) )  SciViews project coordinator (http://www.sciviews.org)
( ( ( ( (
...................................................................
#
On Fri, 16 Apr 2004 11:40:46 +0200 (CEST) phgrosjean@sciviews.org wrote:

            
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.
Z
#
On Fri, 16 Apr 2004 15:44:52 +0200, Achim Zeileis
<Achim.Zeileis@wu-wien.ac.at> wrote :
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
#
On Fri, 16 Apr 2004 09:59:02 -0400 Duncan Murdoch wrote:

            
Of course, yes. Kurt and I have been working on this and as I recall
used mainly vectors and matrices for testing and obviously not 1-way
tables.
Yes, we changed it in that way so that the col, width and offset
arguments are expanded (if necessary) in a similar way. Compare for
example

  x <- cbind(1:3, 2)
  barplot(x, width = 1:2, beside = FALSE)
  barplot(x, width = 1:2, beside = TRUE)

in 1.8.1 and 1.9.0. In the new version the code tries to find a
(statistically) sensible grouping in both cases. One could argue that in
certain cases the widths of each bar should be controlled and they
should not be grouped...depends on what you want to do if length(width)
does not match the number of bars drawn.
Z
#
Please be careful with your replies, folks: you have already created two
new items in R-bugs and so duplicate posts to R-devel.  You need to ensure
that (PR#6776) is on the first line of the subject.
On Fri, 16 Apr 2004, Achim Zeileis wrote: