drmariod
drmariod

Reputation: 11762

Error with facet_wrap since updating ggplot2 to 1.0.1

I have a code snipped which worked fine since last week when I updated ggplot2 from 0.9.3 to 1.0.1.

So basically here is a reproducible example:

df <- data.frame(values=rnorm(200000),
                 title=rep(seq(1,20), each=10000))
ggplot(df, aes(values)) + geom_histogram(binwidth=.08) + facet_wrap(~ title)
ggplot(df, aes(values)) + geom_histogram(binwidth=.05) + facet_wrap(~ title)

In version 0.9.3 it worked with binwidth=.05. Now it returns an error:

Error: arguments imply differing number of rows: 238, 207

I am wondering how to calculate the binwidth in a save way so it will not exit. The standard setting is actually not fine enough for my taste.

Also there are a lot of warning messages which I not completely understand:

1: In loop_apply(n, do.ply) :
  position_stack requires constant width: output may be incorrect

Thanks in advance.

EDIT

Since after a few tests, it seems to work for me sometimes and sometimes not, I also used a seed to make everything reproducible... But in the end, even with a seed, sometimes it works and sometimes not.

Does anyone has an idea how to solve this? I never had problems before updating. Here is the complete output:

> set.seed(123)
> df <- data.frame(values=rnorm(200000),
+                  title=rep(seq(1,20), each=10000))
> ggplot(df, aes(values)) + geom_histogram(binwidth=.05) + facet_wrap(~ title)
Error: arguments imply differing number of rows: 188, 177
In addition: Warning messages:
1: In loop_apply(n, do.ply) :
  position_stack requires constant width: output may be incorrect
2: In loop_apply(n, do.ply) :
  position_stack requires constant width: output may be incorrect
3: In loop_apply(n, do.ply) :
  position_stack requires constant width: output may be incorrect
4: In loop_apply(n, do.ply) :
  position_stack requires constant width: output may be incorrect
5: In loop_apply(n, do.ply) :
  position_stack requires constant width: output may be incorrect
6: In loop_apply(n, do.ply) :
  position_stack requires constant width: output may be incorrect
> ggplot(df, aes(values)) + geom_histogram(binwidth=.08) + facet_wrap(~ title)
> set.seed(123)
> df <- data.frame(values=rnorm(200000),
+                  title=rep(seq(1,20), each=10000))
> ggplot(df, aes(values)) + geom_histogram(binwidth=.05) + facet_wrap(~ title)
There were 20 warnings (use warnings() to see them)
> ggplot(df, aes(values)) + geom_histogram(binwidth=.08) + facet_wrap(~ title)

As you can see, only the first ggplot command gives an error. And after recreating the same data frame, it works and only produces some warnings.

Maybe someone has an idea how to narrow the problem a bit?

Upvotes: 4

Views: 315

Answers (2)

aosmith
aosmith

Reputation: 36076

The warning includes In loop_apply(n, do.ply), which indicates that package plyr might be involved in whatever is going on. When I loaded package plyr_1.8.2 I could reproduce the error.

Updating to the current development version, plyr_1.8.2.9000, solves this issue.

Upvotes: 6

drmariod
drmariod

Reputation: 11762

It looks like the problem is plyr related. Updating to the development version 1.8.2.9000 solved the issue. Thanks @aosmith for pointing this out!

Upvotes: 0

Related Questions