Possible bug in

23 views
Skip to first unread message

Roey Angel

unread,
Mar 6, 2012, 7:09:09 PM3/6/12
to ggp...@googlegroups.com
Hi,
I've been trying to run an old sweave code with the new ggplot2 0.9 and ran into problems with faceting_grid plots. This might be a bug or might very well be something I don't understand about a new functionality in ggplot2.

I'm trying to play around with a fairly large (~30,000 data points) data set and intersect different variables.
The code worked great in the past but since I upgraded to ggplot2 0.9 it spews meaningless facet plots, which seem as if the data was just randomised in plotting regardless of the original categories attached to it.
I haven't encountered any problem in plotting the data using any other ggplot function for the same dataset.
To make sure it is really the new ggplot causing the problem, I reran the same data and code on an old PC with R 2.10.0 and ggplot2 0.8.8 installed on it and the plotting worked as expected (i.e. as it did before)


Here's the plotting function:

plot.tax <- function(data, ...)
  ## plot taxas as bar chart
  # parameters: data.frame; fill/stack; yvar; xvar;
{
    varargin <- list(...)
    if (length(varargin)>0) pos <- varargin[[1]] else pos <- "fill" # determine bar-chart type
    if (as.logical(charmatch('fill',pos,0))) ylab <- 'Fraction' else ylab <- 'Count' # set Y-label according to chart type
    if (length(varargin)>1) yvar <- varargin[[2]] else yvar <- 'Family' # set tax level to plot
    if (length(varargin)>2) {xvar <- varargin[[3]] ; xdat <<- data[,xvar]} # <<- because aes in ggplot only accepts global variables
    else {xvar <- 'Sample' ; xdat <<- xvar}
   
    fill.dat <<-data[,yvar] # get data for filling the bars i.e. tax level
    ggplot(data, aes(x=xdat, fill=fill.dat)) +
    geom_bar(position=pos, colour='white',weight=0.01) +
    labs(fill = yvar) +
    ylab(ylab) +
    xlab('')
}
Which is call and modified as follows

p <- plot.tax(H.ab.tax,"fill", "Order")
p <- p + opts(axis.ticks = theme_blank(), axis.text.x = theme_blank())
p <- p + facet_grid(Climate.Light~Time)
print(p)

The data frame H.ab.tax has several columns but the relevant ones for this function look like this:

Order                  Climate.Light      Time
Bacillales Hyperarid.Dark 1.W
Clostridiales Arid.Dark            1.W
Clostridiales   Arid.Dark 0

The first image is what the figure should look like using ggplot2 0.8.8
and the second is how it looks with ggplot2 0.9 (notice how almost all bars look identical)

Any ideas?

Thanks in advance,
Roey


Roey Angel

unread,
Mar 7, 2012, 7:53:56 AM3/7/12
to ggp...@googlegroups.com
Also, former behaviour could be restored simply by replacing the ggplot2 directory in my R 2.14 with the older one found in my R 2.13 dir (ggplot2 0.89).

Roey

Ista Zahn

unread,
Mar 7, 2012, 8:03:26 AM3/7/12
to Roey Angel, ggp...@googlegroups.com
Hi Roey,

It would help if you could make your example reproducible by including
the data used in the plots.

Best,
Ista

> --
> You received this message because you are subscribed to the ggplot2
> mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

Hadley Wickham

unread,
Apr 11, 2012, 12:06:42 PM4/11/12
to Ista Zahn, Roey Angel, ggp...@googlegroups.com
This bug is now fixed in the development version. You can try it out with

library(devtools)
dev_mode() # remove if you want to replace your existing ggplot2 install
install_github("ggplot2")

Hadley

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages