[R] Problem with facet_grid in ggplot2
diggsb at ohsu.edu
Mon Apr 11 22:27:44 CEST 2011
On 4/11/2011 9:33 AM, Simon Hayward wrote:
> Hi all,
> I am practising a bit with ggplot2 but I have a problem when I try to
> use facet_grid.
> The following code:-
> p<- ggplot(diamonds, aes(carat, ..density..)) +
> + geom_histogram(binwidth = 1)
> p + facet_grid(cut ~ clarity, margins=TRUE)
> produce the following error:-
> Error in class(output[[var]])<- class(value) :
> cannot set class to "array" unless the dimension attribute has length
> I have lifted this code directly from the ggplot2 documentation!
> By a process of elimination it seems that the problem arises from the
> use of margins.
> I do not know why the dimension attribute is conflicting with margins
> unless it is something to do with the properties of the data frame.
> I am running R 2.12.1
> Has the source code changed?
> Very grateful for any help
> Simon Hayward
You have correctly figured out the problem; the margins argument does
not work in facet_grid. It is a known bug. See, for example,
It is still there in ggplot2 0.8.9 (the latest release).
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University
More information about the R-help