dbspitz / migrateR

Shared tools for analyzing animal movement behavior in R
6 stars 0 forks source link

Unable to use plot function with MigrateR #10

Open lbenit opened 4 years ago

lbenit commented 4 years ago

HI, I am using migrateR in R 4.0.2 and cannot get the mvmtClass output to plot using the plot function. The spatmig function is working fine. I have received two different errors from the plot function:

Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double'

Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but does not have components 'x' and 'y'

It does not work with my data nor the bighorn data.

require(migrateR) data(bighorn) bhs.nsd<-mvmtClass(bighorn, stdt = "10-31") plot(bhs.nsd)

I have tried to plot NSD outputs on two windows computers, a mac and with R 3.6.2. All attempts gave me errors. I would be grateful for any help. Sorry if this is a stupid error from my end!

Thanks, Lorena

dbspitz commented 4 years ago

Thanks, Lorena.

Appreciate your reporting the bug, sharing error messages details, and trying this on another machine. Unfortunately, I'm not yet sure what's going on here. I haven't been able to recreate this error on my machine, which makes it tricky to fix. Would you be up for digging a little deeper to help me get a better sense of the problem?

MigrateR defines a new method for plotting objects of class "mvmt". You can find the code for this by returning 'plot.mvmt' in the R console (or on github; this is the code that is run behind the scenes in, e.g., your 'plot( bhs.nsd)' example). If you manually define new objects that match each argument name (e.g., mvmt <- mvmtClass(bighorn)[[1]]; new <- F, etc.), you should be able to run the innards of this function line by line to see where it breaks. Based on the error you report, I expect the issue is with the class of one of the arguments being fed to either the "plot" or "matplot" function calls within plot.mvmt (the 'x' inputs should be vectors, but somehow one is being changed to a list). If you can figure out which argument is causing the error, that would be a big help to me in trying to hone in on a solution.

I could make time toward the end of next week to look into this more, but won't have a chance to dig in myself before then. That said, if this is something you're working on in the meantime, don't hesitate to let me know if you find out more or run into questions!

Also, just out of curiosity, what sort of critters are you working with?

Good luck and keep me posted!

Derek Spitz Postdoc, UCSC Folsom, CA (831) 737-3120 CityOfKitesAndCrows.com http://cityofkitesandcrows.com Wilmers Lab http://wildlife.ucsc.edu // Wittmer Lab http://cms.victoria.ac.nz/sbs/research/ecology-biodiversity-research/ecology-and-conservation-biology

On Thu, Sep 17, 2020 at 9:54 AM lbenit notifications@github.com wrote:

HI, I am using migrateR in R 4.0.2 and cannot get the mvmtClass output to plot using the plot function. The spatmig function is working fine. I have received two different errors from the plot function:

Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double'

  • Comments online related to this error for other packages pointed to an install error, so I reinstall migrateR and have been getting the following error since then.

Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but does not have components 'x' and 'y'

It does not work with my data nor the bighorn data.

require(migrateR) data(bighorn) bhs.nsd<-mvmtClass(bighorn, stdt = "10-31") plot(bhs.nsd)

I have tried to plot NSD outputs on two windows computers, a mac and with R 3.6.2. All attempts gave me errors. I would be grateful for any help. Sorry if this is a stupid error from my end!

Thanks, Lorena

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dbspitz/migrateR/issues/10, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACTZKUXA4SFICJLZVTZSJB3SGI5MXANCNFSM4RQW7THA .

lbenit commented 4 years ago

Thanks for your prompt response! It was super helpful. I tried the following:

plot.mvmt(bhs.nsd[[1]]) and plot.mvmts(bhs.nsd)

Both of the above functions are working beautifully for me. I am not sure why using plot() isn't working.

Additional question: How do you plot the outputs form topmvmt?

And I am working with African elephants.

Thanks, Lorena

dbspitz commented 4 years ago

Weird! Not sure why the call to 'plot' is failing to recognize the mvmt method, but if explicitly calling 'plot.mvmt(s)' does the trick, hopefully that can get you through.

There isn't any built in functionality for plotting only the top model (the thought being that these should usually be viewed within the context provided by other models). You can still approach plotting these individually the same way you'd plot any other model output--using 'fitted' or 'predict' to get y-values. Just be careful if you're planning to combine models from multiple individuals over a single x-axis; depending how you've set things up, matching decimal days from different individuals may refer to different calendar dates.

I'd be curious to hear if you have trouble getting models to provide a good visual fit to any of your elephants. The original models often perform poorly if movements are too complex. If this is something you encounter, a fix is in the works (well, review) and I'm hoping to release it soon.

Best,

Derek Spitz Postdoc, UCSC Folsom, CA (831) 737-3120 CityOfKitesAndCrows.com http://cityofkitesandcrows.com Wilmers Lab http://wildlife.ucsc.edu // Wittmer Lab http://cms.victoria.ac.nz/sbs/research/ecology-biodiversity-research/ecology-and-conservation-biology

On Thu, Sep 17, 2020 at 2:10 PM lbenit notifications@github.com wrote:

Thanks for your prompt response! It was super helpful. I tried the following:

plot.mvmt(bhs.nsd[[1]]) and plot.mvmts(bhs.nsd)

Both of the above functions are working beautifully for me. I am not sure why using plot() isn't working.

Additional question: How do you plot the outputs form topmvmt?

And I am working with African elephants.

Thanks, Lorena

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dbspitz/migrateR/issues/10#issuecomment-694501356, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACTZKUTBNZEKTQBZJBHGIR3SGJ3KXANCNFSM4RQW7THA .

lbenit commented 4 years ago

Thanks!

Yes, some of the models are not fitting well. I haven't added any constraints yet, so I am hoping that resolves some of my issues. I am very interested to read your review.

Best, Lorena