gavinsimpson / ggvegan

ggplot-based plots for vegan
https://gavinsimpson.github.io/ggvegan/
GNU General Public License v2.0
113 stars 30 forks source link

CCA plot issues #23

Closed kohlkopf closed 5 years ago

kohlkopf commented 5 years ago

Unable to use the function autoplot with my vegan produced cca object. I know that cca is intended to be supported, and I see the autoplot.cca.R code.

> cca_model <- vegan::cca(t(X)~.,t(Y)) > autoplot(cca_model) Error: Objects of type cca not supported by autoplot.

If I copy/paste the code from autoplot.cca.R and utils.R and don't have any issues.

gavinsimpson commented 5 years ago

I can only reproduce this if you don't load ggvegan but have loaded ggplot2

r$> library('vegan')
Loading required package: permute
Loading required package: lattice
This is vegan 2.5-5
r$> data(dune)                                                              
r$> data(dune.env)
r$> ord <- cca(dune ~ ., dune.env)

If you haven't loaded ggplot2 you'll see this error

r$> autoplot(ord)
Error in autoplot(ord) : could not find function "autoplot"

If you have gplot2 loaded but not ggvegan then you get the error you saw

r$> library('ggplot2')
r$> autoplot(ord)
Error: Objects of type cca not supported by autoplot.

and it works as expected if you load ggvegan

r$> library('ggvegan')
r$> autoplot(ord)
r$> 
gavinsimpson commented 5 years ago

Do make sure you have done:

## install.packages('remotes') # if you don't have this installed
remotes::install_github('gavinsimpson/ggvegan')
library('ggvegan')

before trying to use functions from the package.

That this works when you load the .R scripts you mention indicates that the package isn't loaded.

kohlkopf commented 5 years ago

Good catch! Sorry for the SPAM.