hugomflavio / actel

Standardised analysis of acoustic telemetry data from fish moving through receiver arrays
https://hugomflavio.github.io/actel-website
26 stars 5 forks source link

PlotRatios #77

Closed thortb95 closed 2 years ago

thortb95 commented 2 years ago

Hi! I´m trying running plotRatios and this work fine when I just run: plotRatios(res.results) image

But I get sections I don't want, like "Fjord-River_mouth" and "Fjord-Lake". I select sections: plotRatios(res.results, sections = c("Fjord", "River_mouth", "River_mouth-Lake", "Lake"), type = "percentages") This works, but when I change type to "absolutes" it doesn't work anymore. I also get color by group, something I don't want, I just want the figure without the mentioned sections. Is this possible? :)

image

hugomflavio commented 2 years ago

Hi!

Thanks for reaching out! It seems to me there are two separate issues here. I discuss them below.

# Let's make a minimal working example

library('actel')
example.residency.results <- c(example.results, additional.residency.results)
example.residency.results$rsp.info$analysis.type <- "residency"

# Problem 1: 'Undefined columns selected' error

plotRatios(example.residency.results) # note that type = 'absolutes' is the default

plotRatios(example.residency.results, sections = c('River', 'River-Fjord')) # works

plotRatios(example.residency.results, sections = c('River', 'River-Fjord'), type = 'percentages') # works

plotRatios(example.residency.results, sections = c('River', 'Fjord-Sea')) # does not work! <----- !!!!
# Error in `[.data.frame`(x, , c(1, match(sections, colnames(x)))) : 
#   undefined columns selected

plotRatios(example.residency.results, sections = c('River', 'Fjord-Sea'), type = 'percentages') # works

# Problem 2: Labelling a partial plot by section rather than by group

# Currently not possible. It would require a new argument, e.g.: 'colour.by', with values 'default', 'section', 'group'.

Regarding problem 1, congratulations, you found a bug! :sweat_smile: I will look into it and upload a fix as soon as I can. Regarding problem 2, as stated, the mechanism you are looking for does not exist yet, but I can make it happen. I will likely need some days to look into this, but once I have it working locally I will let you know!

thortb95 commented 2 years ago

Thank u so much for your answers! woho my first bug. I´m waiting :D

hugomflavio commented 2 years ago

Update: The error occurs here. When a group does not show up at one of the required sections, the column doesn't exist, leading to the selection of 'undefined columns'. Changing the matching mechanism will fix this, just got to make sure the system doesn't do partial matches (temporarily making a placeholder column filled with 0's might be safer?). This brings up the need to consider what would happen if the group was not detected at any of the requested sections.

More updates to come.

hugomflavio commented 2 years ago

@thortb95 The latest development version should both 1) fix the bug and 2) allow you to chose how to colour the plots using the new col.by argument. e.g. plotRatios(res.results, sections = c("Fjord", "River_mouth", "River_mouth-Lake", "Lake"), type = "percentages", col.by = "section")

Would you mind trying it out and letting me know how it goes? Follow the instructions below to install the dev version:

# If you don't have the package "remotes" installed, start with:
install.packages("remotes")

# This will install actel's development version:
remotes::install_github("hugomflavio/actel"
            build_opts = c("--no-resave-data", "--no-manual"),
            build_vignettes = TRUE)

library("actel")
# The displayed version should now be 1.2.1.9012
# If that is not the case, unload actel and load it again.

Thanks!

hugomflavio commented 2 years ago

Closing this one due to inactivity. Hopefully the error is fixed :)