You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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…
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
#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))
)
)
The text was updated successfully, but these errors were encountered:
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…
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(
)
The text was updated successfully, but these errors were encountered: