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

