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

Example figure for summarizing stock composition in fisheries #4

Open
ccooktabor opened this issue Jan 4, 2022 · 0 comments
Open

Comments

@ccooktabor
Copy link
Collaborator

A few Southern Panel members requested we include summary information on fishery stock composition. In the summer of 2020, Angelika, myself, and Dan worked on creating figures to meet this request. While much progress was made, some tweaks are still needed (like combining some of the FRAM stocks into MUs - or just renaming them to be clearer to the reader), among other things. Here is a record of the conversation and the code that Dan last provided on this subject in an email dated 8-19-2020:

Thanks Carrie. In that code it looks like the fct_reorder needs to move into the initiating aes() in L58 rather than have it as a stand-alone in L62. (R/ggplot doesn’t know what to do with it there after a chaining “+”) However, it also looks like geom_bar is being called with a y-aesthetic, which ggplot doesn’t like. I think you’re getting around that with stat=”identity”, but geom_col would probably be preferable when you’ve already calculated and identified the y values.

Other than that, rather than modify your code, it was fastest for me to just do a version of more-or-less what I think you’re after. See below. Note that it looks like things are “mis-ordered” for a couple of stocks, but that’s because the data have identical strings for multiple stock ids (e.g., “Youngs Bay Hatchery” for 167 and 168) so the multiple rows of “Proportion” are being summed for each character/factor level of “Stock”. You’d need to relabel the Stock column with more info (mark status?) or do the re-order on StockID (second plot). You might also consider adding the “prop_thresh” value into the plot subtitle or such…

image
image

library("tidyverse")

theme_set(theme_light())

d <- read_csv("C:/Users/auerbdaa/Downloads/CohoMortalitiesSummary2010to18post.csv")

prop_thresh <- 0.0099

#not really sure what "AvgTotMort" is, but this calcs the per-stock proportion of the sum of AvgTotMort per fishery

d %>%

group_by(Fishery) %>%

mutate(Proportion = AvgTotMort / sum(AvgTotMort)) %>%

ungroup() %>%

filter(Proportion > prop_thresh) %>%

#for dev/testing...

filter(Fishery ID < 7) %>%

#break into a list of tibbles

split(.$Fishery) %>%

#do a thing to each table: here builds a list of ggplot objects

#you could assign to a new object and iterate png writes or whatever

map(

~.x %>% #".x" here is each tibble per-Fishery and the tilde makes the whole thing an implicit function

  ggplot(aes(x = fct_reorder(Stock, Proportion, min), y = Proportion)) +

   #ggplot(aes(x = fct_reorder(as.character(`Stock ID`), Proportion, min), y = Proportion)) +

  geom_col() + #do whatever you want to colors etc

  coord_flip() + xlab("FRAM Stock") + ylab("Proportion of Catch") +

  labs(

    title = paste(.x$Fishery[1], ":", sum(.x$AvgTotMort))

  )

)

ccooktabor added a commit that referenced this issue Jul 9, 2024
ccooktabor added a commit that referenced this issue Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant