CCA with Vegan - Plot problem

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

CCA with Vegan - Plot problem

rumble14
Hi,
I've just started using R and am having some problems with CCA using vegan.

I'm looking at abundance p/m2 (hence decimals) vs environmental variables and have been using http://ecology.msu.montana.edu/labdsv/R/labs/lab12/lab12.html to guide me through.

My organism data looks like this:
Sample      "Species_1"   "Species_2"   "Species_3"   etc
Sample_1   0                       0.12432          0.3456
etc

and is in a .csv file

My environment data (.csv again) looks like this:
Temp    Water   etc
18            33.3
etc

I can get vegan to run the CCA with no problems but when I enter

>cca1.plot <- plot(cca.1,choices=c(1,2))

I get the following error message:

Error in function (formula, data = NULL, subset = NULL, na.action = na.fail,  :
  invalid type (list) for variable 'org'

('org' is the name of my organism file once attached).

I'd appreciate some help. If I haven't given enough detail, please let me know. I've tested the example data given on the website and it works so am obviously missing something I shouldn't be.

Cheers,
Heather
Reply | Threaded
Open this post in threaded view
|

Re: CCA with Vegan - Plot problem

Gavin Simpson
On Fri, 2012-11-09 at 00:51 -0800, rumble14 wrote:

> Hi,
> I've just started using R and am having some problems with CCA using vegan.
>
> I'm looking at abundance p/m2 (hence decimals) vs environmental variables
> and have been using
> http://ecology.msu.montana.edu/labdsv/R/labs/lab12/lab12.html to guide me
> through.
>
> My organism data looks like this:
> Sample      "Species_1"   "Species_2"   "Species_3"   etc
> Sample_1   0                       0.12432          0.3456
> etc
>
> and is in a .csv file
>
> My environment data (.csv again) looks like this:
> Temp    Water   etc
> 18            33.3
> etc
>
> I can get vegan to run the CCA with no problems but when I enter
>
> >cca1.plot <- plot(cca.1,choices=c(1,2))
>
> I get the following error message:
>
> Error in function (formula, data = NULL, subset = NULL, na.action = na.fail,
> :
>   invalid type (list) for variable 'org'
>
> ('org' is the name of my organism file once attached).

Somewhat frustratingly you have covered everything *but* how you created
`cca.1` and whilst you might presume that because an error was not
thrown everything worked out OK with that procedure, the failing
`plot()` call suggests otherwise.

Can you show the exact code you used please? Also, not sure why you are
attaching anything - it is not required for most R usage and certainly
not for using cca() in vegan.

G

> I'd appreciate some help. If I haven't given enough detail, please let me
> know. I've tested the example data given on the website and it works so am
> obviously missing something I shouldn't be.
>
> Cheers,
> Heather
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/CCA-with-Vegan-Plot-problem-tp4649012.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: CCA with Vegan - Plot problem

rumble14
Thanks for replying. Apologies for not putting the code, I have not deviated from that used on the website I linked to.

>Can you show the exact code you used please?

I am using:
#below is Species_1 etc
org <- read.table ("Organisms.S", header=TRUE, row.names=1)
#below is environmental variables
env<-read.table ("Environment.S, header=TRUE)
attach(env)
library(vegan)
cca.1<-(org~Temp+Water+etc)
cca.1

At this point I have noticed (this morning) that I should be getting the CCA come up here, and this is working with test data but not my actual data which is formatted in exactly the same way.
If I type:

cca(formula = org ~ Temp + Water+etc, data = org)

at this point, I get what looks like but (you're right) might not be an output.
For the graph I was then trying to use:

cca1.plot <- plot(cca.1,choices=c(1,2))

at which point I get error messages.


>Also, not sure why you are
attaching anything

As I said, I'm quite new to R. It does so on the tutorial linked so  had assumed it was to do with being able to access the parameters Temp etc.

H


Reply | Threaded
Open this post in threaded view
|

Re: CCA with Vegan - Plot problem

rumble14
Sorry, just to clarify as I have put .S files in the later response but .csv in the earlier, I have tried with both, changing to read.csv or read.table as appropriate but get the same play of events.
H
Reply | Threaded
Open this post in threaded view
|

Re: CCA with Vegan - Plot problem

Gavin Simpson
In reply to this post by rumble14
On Fri, 2012-11-09 at 05:16 -0800, rumble14 wrote:

> Thanks for replying. Apologies for not putting the code, I have not deviated
> from that used on the website I linked to.
>
> >Can you show the exact code you used please?
>
> I am using:
> #below is Species_1 etc
> org <- read.table ("Organisms.S", header=TRUE, row.names=1)
> #below is environmental variables
> env<-read.table ("Environment.S, header=TRUE)
> attach(env)
> library(vegan)
> cca.1<-(org~Temp+Water+etc)
> cca.1

Don't do that - it is an abuse of the formula interface and an
abomination to attach such objects to the search path.

This isn't actually doing anything (well, it is, but it is not a CCA):

cca.1<-(org~Temp+Water+etc)

There is no function call. And your use of `+ etc` suggests this isn't
the **actual** code you ran and I did ask for that. You should use:

cca.1 <- cca(org ~ ., data = env)

assuming you want all variables in `env` in the model - not that that is
a good thing but that is a statistical issue not an R one!

Can you show me - probably *off list* including the actual data files
(which I promise to delete after we solve the problem) - the code you
use and I can take a look but before you send anything to me in an email
make sure you can paste the exact same code into R and have it run

G

> At this point I have noticed (this morning) that I should be getting the CCA
> come up here, and this is working with test data but not my actual data
> which is formatted in exactly the same way.
> If I type:
>
> cca(formula = org ~ Temp + Water+etc, data = org)
>
> at this point, I get what looks like but (you're right) might not be an
> output.
> For the graph I was then trying to use:
>
> cca1.plot <- plot(cca.1,choices=c(1,2))
>
> at which point I get error messages.
>
>
> >Also, not sure why you are
> attaching anything
>
> As I said, I'm quite new to R. It does so on the tutorial linked so  had
> assumed it was to do with being able to access the parameters Temp etc.
>
> H
>
>
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/CCA-with-Vegan-Plot-problem-tp4649012p4649045.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.