Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No ggplot2 graphs are working: "Error in y[setdiff(names(y), names(x))] : object of type 'closure' is not subsettable"

Tags:

r

ggplot2

I'm new to R, and struggling to get ggplot2 to reliably work. Even simple code snippets that have been reproduced elsewhere are failing on my machine.

This:

library(ggplot2)
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) + geom_point()

Gives me:

Error in y[setdiff(names(y), names(x))] : object of type 'closure' is not subsettable

Importantly, this was working yesterday. I can't think of anything that changed. Now it's not.

I've reinstalled R, Rstudio and ggplot2 to no avail. My guess is that there's a versioning problem somewhere, but am not sure.

Thanks for any help.

UPDATE

Here's the output from sessioninfo():

R version 3.3.0 (2016-05-03)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.5 (Yosemite)

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

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

other attached packages:
[1] ggrepel_0.5   scales_0.4.0  ggplot2_2.1.0

loaded via a namespace (and not attached):
[1] labeling_0.3     colorspace_1.2-6 plyr_1.8.3       tools_3.3.0             
gtable_0.2.0    
[6] Rcpp_0.12.5      grid_3.3.0       munsell_0.4.3   
like image 866
Max Avatar asked Jun 03 '16 21:06

Max


1 Answers

I can reproduce this error message if I set an invalid default theme. For example:

library(ggplot2)
theme_set(theme_bw) # improper usage of theme_set, should be theme_set(theme_bw())
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) + geom_point()

gives me the error

Error in y[setdiff(names(y), names(x))] : 
object of type 'closure' is not subsettable

but

library(ggplot2)
theme_set(theme_bw()) # have now fixed theme_bw
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) + geom_point()

works fine.

like image 73
Peter Harrison Avatar answered Nov 14 '22 03:11

Peter Harrison