Problem with facets + margins

67 views
Skip to first unread message

anovember

unread,
Jul 21, 2010, 2:01:13 AM7/21/10
to ggplot2
the following plot code bombs out... any suggestions?

qplot(mpg, wt, data = mtcars) + facet_grid(vs ~ am,margins=T)

Error in class(output[[var]]) <- class(value) :
cannot set class to "array" unless the dimension attribute has
length > 0


> sessionInfo()
R version 2.11.1 (2010-05-31)
i386-apple-darwin9.8.0



locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] splines stats graphics grDevices utils datasets
grid
[8] methods base

other attached packages:
[1] Hmisc_3.8-2 survival_2.35-8 ez_1.6.1 car_1.2-16
[5] ggplot2_0.8.8 proto_0.3-8 reshape_0.8.3 plyr_1.0.3

loaded via a namespace (and not attached):
[1] cluster_1.12.3 digest_0.4.2 lattice_0.18-8

Dennis Murphy

unread,
Jul 21, 2010, 3:53:47 AM7/21/10
to anovember, ggplot2
Why do you need margins = TRUE? What is wrong with the plot if you take that argument out?

BTW, the same error shows up by running the following from the facet_grid() help page:

> p <- ggplot(diamonds, aes(carat, ..density..)) +
+  geom_histogram(binwidth = 1)
> p
> p + facet_grid(cut ~ clarity)
> p + facet_grid(cut ~ clarity, margins=TRUE)

Error in class(output[[var]]) <- class(value) :
  cannot set class to "array" unless the dimension attribute has length > 0

Dennis



--
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

Joe

unread,
Jul 21, 2010, 12:35:13 PM7/21/10
to ggplot2
I just encountered this too. Here's code from the ggplot2 book.

mpg2 <- subset(mpg, cyl != 5 & drv %in% c("4", "f"))

p <- qplot(displ, hwy, data = mpg2) +
geom_smooth(method = "lm", se = F)

p + facet_grid(cyl ~ drv, margins = T)

The last line gives me the same error:

Error in class(output[[var]]) <- class(value) :
cannot set class to "array" unless the dimension attribute has
length > 0

But, it should create the right hand plot in figure 7.2
> > To unsubscribe: email ggplot2+u...@googlegroups.com<ggplot2%2Bunsu...@googlegroups.com >
> > More options:http://groups.google.com/group/ggplot2

Hadley Wickham

unread,
Jul 21, 2010, 1:18:48 PM7/21/10
to Joe, ggplot2
Yup, margins are broken in the current version. Should be fixed in
the next couple of weeks.
Hadley

> More options: http://groups.google.com/group/ggplot2
>

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

anovember

unread,
Jul 21, 2010, 1:44:58 PM7/21/10
to ggplot2

That's the bug. If I try to include the margins, it throws an error.

Thanks,
-A

Hadley Wickham

unread,
Jul 21, 2010, 3:01:14 PM7/21/10
to Joe, ggplot2
I should mention that there is a work around:

qplot(mpg, wt, data = add_margins(mtcars, rows = "vs", cols = "am")) +
facet_grid(vs ~ am)

But that exposes another bug :(

Hadley

Ista Zahn

unread,
Sep 15, 2010, 3:30:14 PM9/15/10
to Hadley Wickham, Joe, ggplot2
Hi Hadley,
I could have sworn this issue was fixed, but either I was wrong about
that or it has reappeared. Margins don't seem to work at all in
version 0.8.8 with plyr 1.2.1 and reshape 0.8.3. For example:

library(ggplot2)
p <- qplot(displ, hwy, data = mpg) + geom_point()
p + facet_grid(cyl ~ drv, margins = TRUE)

> sessionInfo()
R version 2.11.1 (2010-05-31)

i686-pc-linux-gnu

locale:
[1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C
[3] LC_TIME=en_US.utf8 LC_COLLATE=en_US.utf8
[5] LC_MONETARY=C LC_MESSAGES=en_US.utf8
[7] LC_PAPER=en_US.utf8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C

attached base packages:
[1] grid stats graphics grDevices utils datasets methods
[8] base

other attached packages:
[1] ggplot2_0.8.8 proto_0.3-8 reshape_0.8.3 plyr_1.2.1

loaded via a namespace (and not attached):

[1] tools_2.11.1

Best,
Ista

--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

Hadley Wickham

unread,
Sep 15, 2010, 8:17:19 PM9/15/10
to Ista Zahn, Joe, ggplot2
Yes, that's been broken for a while unfortunately. Will try and work on soon.
Hadley
Reply all
Reply to author
Forward
0 new messages