Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add function to show presence/absence by depth bin? #31

Closed
Tracked by #49
iantaylor-NOAA opened this issue Feb 19, 2021 · 13 comments · Fixed by #94
Closed
Tracked by #49

add function to show presence/absence by depth bin? #31

iantaylor-NOAA opened this issue Feb 19, 2021 · 13 comments · Fixed by #94

Comments

@iantaylor-NOAA
Copy link
Contributor

The figure below was created for the 2019 Big Skate assessment as a simple illustration of the depth distribution of the species, where the width of each bar is proportional to the number of tows within that depth bin. In this case of Big Skate it was useful to see that the modal depth was likely near or shallower than the 55m minimum of the survey.

Would it be useful to generalize this for application to any species which occurs in the WCGBT Survey?
If so, I would provide inputs to choose the latitude range, depth range, and depth bin size and any other refinements that anyone suggests.

Code is at https://github.com/iantaylor-NOAA//BigSkate_Doc/blob/master/R/Depth_explorations.R

WCGBTS_presence_absence_by_depth_bin

@chantelwetzel-noaa
Copy link
Contributor

I think this type of addition would be great. I have a few other plots that I have been working on for survey visualization. One of them is a similar to your above (not nearly as pretty) which shows the percent positive tows by year. I think we could also do a similar plot to your but have it across latitudes. I will not be able to incorporate any of this new plotting functionality in the next couple of months but that could give us time to identify a needed suite of plots and how best to create the code (e.g. something similar to SS_plots that would do a full set of plots calling separate plotting functions internally).

@iantaylor-NOAA
Copy link
Contributor Author

New function PlotPresenceAbsence.fn() added in commit 253248d.

Example commands below from ?PlotPresenceAbsence.fn produces the figures below

catch.WCGBTS.ling <- nwfscSurvey::PullCatch.fn(Name = "lingcod",
                                               SurveyName = "NWFSC.Combo")
PlotPresenceAbsence.fn(catch.WCGBTS.ling, dim = "lat")
PlotPresenceAbsence.fn(catch.WCGBTS.ling, dim = "depth")

Presence-absence_by_depth_in_WCGBT_Survey
Presence-absence_by_latitude_in_WCGBT_Survey

@chantelwetzel-noaa
Copy link
Contributor

Thank you @iantaylor-NOAA. I used the example code that you sent to create plots for Dover sole and it was super informative. Based on my playing around with Dover sole, I have some ideas of options and features that will create reasonable plots across species. This give us a create start for development. To help foster additional ideas here are the modified plots that I created for Dover sole (with Ian's help I can make great plots too!):

WCGBTS_presence_by_depth_bin

@iantaylor-NOAA
Copy link
Contributor Author

Nice Dover plots, Chantel.
I should have noted that I have not tested this on anything other than Lingcod, so please modify as you wish for other species and other features.

@chantelwetzel-noaa
Copy link
Contributor

chantelwetzel-noaa commented Feb 24, 2021

Quick question. I inferred that the width of the bins in your example are related to the cpue by bin (e.g., higher cpue would result in wider bin). Is this correct? I standardized everything for Dover sole because the numbers of observations across depths and the size of positive tows was a bit messy since it is the extreme end for trawl species. I think both options would be useful.

@iantaylor-NOAA
Copy link
Contributor Author

I believe widths are proportional to the number of tows within each bin, which I think is also useful information, but I could see how it could add confusion for a species like Dover that spans all depths everywhere.

100% of the plotting code in this function is done in the single line
https://github.com/nwfsc-assess/nwfscSurvey/blob/5f160c1736832141f9cb369aa5a9504e3cd0ad84/R/PlotPresenceAbsence.fn.R#L127
where using plot() on a 2-dimensional table calls plot.table() which then apparently calls mosaicplot(). I have no idea how you change the widths of the bars or anything else (other than the color, I guess).

@kellijohnson-NOAA
Copy link
Contributor

@iantaylor-NOAA and @chantelwetzel-noaa would you mind if I changed the x-axis bin labels to be on an angle because the values often overlap (e.g., see Ian's example above and the example below).
Presence-absence_by_depth_in_WCGBT_Survey

@kellijohnson-NOAA
Copy link
Contributor

Found that las = 3 can easily change the labels to always be vertical, which we could do by just adding ... to the args to allow people to pass arguments to plot, e.g., las = 3 which makes the following and does not force people to use vertical labels.
image

@chantelwetzel-noaa
Copy link
Contributor

That is great. Feel free to commit this change. I plan on working more on this plotting function today or next week to incorporate additional revisions that I explored when creating a figure for Dover sole to make it more versatile.

kellijohnson-NOAA added a commit that referenced this issue Nov 22, 2022
Deprecates `dopng =` because dir = NULL can serve as FALSE.

* Remove importsFrom for two functions with ::
* Uses ifelse to create main_ to remove
  so many if statements with duplicated code.
* Uses on.exit to call dev.off() in case the function fails, then the
  device is not left on.
*  fix(PlotPresenceAbsence.fn):
  * dim: `match.arg` allows you to list all of the possible options in
    the function call so users know what is available. Then, `match.arg`
    will use the first listed as the default.
  * Uses dontrun plot b/c the figures and download take too long and
    `check()` complains. So, I wrapped them in dontrun{} and I added an
    example with the package data where you do not have to download
    anything.
  * Checked spelling in documentation and wrapped at 80 characters.

Part of #31

TODO:
* Use `ggplot2::ggsave()`
* Remove the call to windows() which only works on windows machines and
  will cause GitHub actions to fail if there was a test.
kellijohnson-NOAA added a commit that referenced this issue Nov 22, 2022
Deprecates `dopng =` because dir = NULL can serve as FALSE.

* Remove importsFrom for two functions with ::
* Uses ifelse to create main_ to remove
  so many if statements with duplicated code.
* Uses on.exit to call dev.off() in case the function fails, then the
  device is not left on.
*  fix(PlotPresenceAbsence.fn):
  * dim: `match.arg` allows you to list all of the possible options in
    the function call so users know what is available. Then, `match.arg`
    will use the first listed as the default.
  * Uses dontrun plot b/c the figures and download take too long and
    `check()` complains. So, I wrapped them in dontrun{} and I added an
    example with the package data where you do not have to download
    anything.
  * Checked spelling in documentation and wrapped at 80 characters.

Part of #31

TODO:
* Use `ggplot2::ggsave()`
* Remove the call to windows() which only works on windows machines and
  will cause GitHub actions to fail if there was a test.
kellijohnson-NOAA added a commit that referenced this issue Nov 22, 2022
Deprecates `dopng =` because dir = NULL can serve as FALSE.

* Remove importsFrom for two functions with ::
* Uses ifelse to create main_ to remove
  so many if statements with duplicated code.
* Uses on.exit to call dev.off() in case the function fails, then the
  device is not left on.
*  fix(PlotPresenceAbsence.fn):
  * dim: `match.arg` allows you to list all of the possible options in
    the function call so users know what is available. Then, `match.arg`
    will use the first listed as the default.
  * Uses dontrun plot b/c the figures and download take too long and
    `check()` complains. So, I wrapped them in dontrun{} and I added an
    example with the package data where you do not have to download
    anything.
  * Checked spelling in documentation and wrapped at 80 characters.

Part of #31

TODO:
* Use `ggplot2::ggsave()`
* Remove the call to windows() which only works on windows machines and
  will cause GitHub actions to fail if there was a test.
kellijohnson-NOAA added a commit that referenced this issue Nov 22, 2022
Deprecates `dopng =` because dir = NULL can serve as FALSE.

* Remove importsFrom for two functions with ::
* Uses ifelse to create main_ to remove
  so many if statements with duplicated code.
* Uses on.exit to call dev.off() in case the function fails, then the
  device is not left on.
*  fix(PlotPresenceAbsence.fn):
  * dim: `match.arg` allows you to list all of the possible options in
    the function call so users know what is available. Then, `match.arg`
    will use the first listed as the default.
  * Uses dontrun plot b/c the figures and download take too long and
    `check()` complains. So, I wrapped them in dontrun{} and I added an
    example with the package data where you do not have to download
    anything.
  * Checked spelling in documentation and wrapped at 80 characters.

Part of #31

TODO:
* Use `ggplot2::ggsave()`
* Remove the call to windows() which only works on windows machines and
  will cause GitHub actions to fail if there was a test.
@kellijohnson-NOAA
Copy link
Contributor

I created a branch plot_presence that has a function that can {ggplot2} versions these figures. I pushed a wrapper as well that saves the CPUE by depth and latitude and we can easily add sex to the wrapper but I just haven't yet. Below are the CPUE figures. Let me know what you think. @chantelwetzel-noaa they don't have white backgrounds because then you cannot see the gridlines, which I think are helpful. I can change this though, no problem.
presence-absence_by_depth
presence-absence_by_latitude

@chantelwetzel-noaa
Copy link
Contributor

These figures look good. In my limited experience creating barplots with ggplot2, I had issues where there was white space between the figure and the axes but you have solved that issue. Have you successfully create these similar figures with equally sized bars across the x-axis? I think having that option is fairly important for species with wide depth distributions (e.g., Dover sole, sablefish, thornyheads).

@kellijohnson-NOAA
Copy link
Contributor

This can be accomplished now with type = c("vspine", "hbar") which is some ggmosaic::geom_mosaic(divider = ) black magic.

@chantelwetzel-noaa
Copy link
Contributor

Can you give me and example call for this? I just tested this out by using:

plot_bin_factor( data = bio_nwfsc_combo %>% dplyr::mutate(Sex = codify_sex(Sex)), col_factor = Sex, col_bin = Depth_m, type = c("vspine", "hbar"), width = 50, boundary = 0 ) + scale_fill_manual(values = c("red", "blue", "gray"))
which produced this figure:

dover_sex_depth

This is a fine way to look at this but I would also like to be able to produce the sex ratio where the proportions by sex sum to 1.

@kellijohnson-NOAA kellijohnson-NOAA linked a pull request Dec 1, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants