Skip to content

Commit

Permalink
remove log(R0) and update figures
Browse files Browse the repository at this point in the history
  • Loading branch information
Bai-Li-NOAA committed Jun 25, 2024
1 parent bd5104c commit 5501818
Show file tree
Hide file tree
Showing 102 changed files with 2,121 additions and 1,667 deletions.
Binary file removed TextAnalysis/top10_barplot_mean.jpg
Binary file not shown.
105 changes: 0 additions & 105 deletions TextAnalysis/top10_frequency.csv

This file was deleted.

105 changes: 0 additions & 105 deletions TextAnalysis/top10_presence.csv

This file was deleted.

105 changes: 0 additions & 105 deletions TextAnalysis/top10_proportion.csv

This file was deleted.

82 changes: 41 additions & 41 deletions TextAnalysis/top20_analysis.R → TextAnalysis/top19_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ if (authorize_GoogleDrive) {
)
}


# run_text_mining function ------------------------------------------------

run_text_mining <- function(keyword, xlabels, working_path,
Expand Down Expand Up @@ -199,9 +198,9 @@ run_text_mining <- function(keyword, xlabels, working_path,
)
proportion_database[nrow(proportion_database), "ID"] <- "Sum"

write.csv(frequency_database, file=here::here("TextAnalysis", paste0("top20_frequency_", names(subfolder_info)[org], "_", scenario_name, ".csv")), row.names=FALSE)
write.csv(presence_database, file=here::here("TextAnalysis", paste0("top20_presence_", names(subfolder_info)[org], "_", scenario_name, ".csv")), row.names=FALSE)
write.csv(proportion_database, file=here::here("TextAnalysis", paste0("top20_proportion_", names(subfolder_info)[org], "_", scenario_name, ".csv")), row.names=FALSE)
write.csv(frequency_database, file=here::here("TextAnalysis", paste0("top19_frequency_", names(subfolder_info)[org], "_", scenario_name, ".csv")), row.names=FALSE)
write.csv(presence_database, file=here::here("TextAnalysis", paste0("top19_presence_", names(subfolder_info)[org], "_", scenario_name, ".csv")), row.names=FALSE)
write.csv(proportion_database, file=here::here("TextAnalysis", paste0("top19_proportion_", names(subfolder_info)[org], "_", scenario_name, ".csv")), row.names=FALSE)
# Upload xlsx to Google Drive
if (authorize_GoogleDrive) {
# Google Drive folder id
Expand All @@ -210,17 +209,17 @@ run_text_mining <- function(keyword, xlabels, working_path,
}

# Plot results ------------------------------------------------------------
frequency_database <- read.csv(file=here::here("TextAnalysis", paste0("top20_frequency_", names(subfolder_info)[org], "_", scenario_name, ".csv")))
presence_database<-read.csv(file=here::here("TextAnalysis", paste0("top20_presence_", names(subfolder_info)[org], "_", scenario_name, ".csv")))
proportion_database<-read.csv(file=here::here("TextAnalysis", paste0("top20_proportion_", names(subfolder_info)[org], "_", scenario_name, ".csv")))
frequency_database <- read.csv(file=here::here("TextAnalysis", paste0("top19_frequency_", names(subfolder_info)[org], "_", scenario_name, ".csv")))
presence_database<-read.csv(file=here::here("TextAnalysis", paste0("top19_presence_", names(subfolder_info)[org], "_", scenario_name, ".csv")))
proportion_database<-read.csv(file=here::here("TextAnalysis", paste0("top19_proportion_", names(subfolder_info)[org], "_", scenario_name, ".csv")))

word_frequency <- as.matrix(frequency_database[frequency_database$ID == "Sum", 4:ncol(frequency_database)])
word_presence <- as.matrix(presence_database[presence_database$ID == "Sum", 4:ncol(presence_database)])
word_presence_mean <- as.matrix(presence_database[presence_database$ID == "Sum", 4:ncol(presence_database)])/(nrow(presence_database)-1)*100
word_proportion <- as.matrix(proportion_database[proportion_database$ID == "Sum", 4:ncol(proportion_database)])

# barplot
jpeg(filename = here::here("TextAnalysis", paste0("top20_barplot_", names(subfolder_info)[org], "_", scenario_name, ".jpg")), width = 200, height = 120, units = "mm", res = 1200)
jpeg(filename = here::here("TextAnalysis", paste0("top19_barplot_", names(subfolder_info)[org], "_", scenario_name, ".jpg")), width = 200, height = 120, units = "mm", res = 1200)
par(mar = c(6, 4, 1, 1), mfrow = c(3, 1))
frequency_barplot <- barplot(height = word_frequency, xaxt = "n", ylab = "Frequency")
text(frequency_barplot - 0.25, par("usr")[3] - 0.25, xlabels, xpd = TRUE, srt = 40, adj = 1, cex = 0.8)
Expand All @@ -234,20 +233,20 @@ run_text_mining <- function(keyword, xlabels, working_path,

dev.off()

jpeg(filename = here::here("TextAnalysis", paste0("top20_presence_", names(subfolder_info)[org], "_", scenario_name, ".jpg")), width = 200, height = 120, units = "mm", res = 1200)
jpeg(filename = here::here("TextAnalysis", paste0("top19_presence_", names(subfolder_info)[org], "_", scenario_name, ".jpg")), width = 200, height = 120, units = "mm", res = 1200)
par(mar = c(6, 4, 1, 1), mfrow = c(1, 1))
presence_barplot <- barplot(height = word_presence, xaxt = "n", ylab = "Presence (%)")
text(presence_barplot - 0.25, par("usr")[3] - 0.25, xlabels, xpd = TRUE, srt = 40, adj = 1, cex = 0.7)
dev.off()

jpeg(filename = here::here("TextAnalysis", paste0("top20_presence_mean_", names(subfolder_info)[org], "_", scenario_name, ".jpg")), width = 200, height = 120, units = "mm", res = 1200)
jpeg(filename = here::here("TextAnalysis", paste0("top19_presence_mean_", names(subfolder_info)[org], "_", scenario_name, ".jpg")), width = 200, height = 120, units = "mm", res = 1200)
par(mar = c(6, 4, 1, 1), mfrow = c(1, 1))
presence_barplot <- barplot(height = word_presence_mean, xaxt = "n", ylab = "Presence (%)")
text(presence_barplot - 0.25, par("usr")[3] - 0.25, xlabels, xpd = TRUE, srt = 40, adj = 1, cex = 0.7)
dev.off()

# wordcloud figure
jpeg(filename = here::here("TextAnalysis", paste0("top20_wordcloud_", names(subfolder_info)[org], "_mean_presence_grays", "_", scenario_name, ".jpg")), width = 200, height = 200, units = "mm", res = 1200)
jpeg(filename = here::here("TextAnalysis", paste0("top19_wordcloud_", names(subfolder_info)[org], "_mean_presence_grays", "_", scenario_name, ".jpg")), width = 200, height = 200, units = "mm", res = 1200)
par(mar = c(0.1, 0.1, 0.1, 0.1), mfrow = c(1, 1))
set.seed(123)
wordcloud(
Expand All @@ -261,7 +260,7 @@ run_text_mining <- function(keyword, xlabels, working_path,
text(0.1, 0.8, scenario_name)
dev.off()

jpeg(filename = here::here("TextAnalysis", paste0("top20_wordcloud_", names(subfolder_info)[org], "_mean_presence_black", "_", scenario_name, ".jpg")), width = 200, height = 200, units = "mm", res = 1200)
jpeg(filename = here::here("TextAnalysis", paste0("top19_wordcloud_", names(subfolder_info)[org], "_mean_presence_black", "_", scenario_name, ".jpg")), width = 200, height = 200, units = "mm", res = 1200)
par(mar = c(0.1, 0.1, 0.1, 0.1), mfrow = c(1, 1))
set.seed(123)
wordcloud(
Expand All @@ -281,52 +280,56 @@ working_path <- here::here("StockAssessment")
subfolder_path_all <- list.dirs(path = working_path, full.names = TRUE, recursive = FALSE)
subfolder_name_all <- list.dirs(path = working_path, full.names = FALSE, recursive = FALSE)

subfolder_info <- list(1, 2, 3:length(subfolder_path_all), 1:length(subfolder_path_all))
subfolder_info <- list(
grep("Australia", subfolder_name_all),
grep("ICES", subfolder_name_all),
grep("NOAA", subfolder_name_all),
1:length(subfolder_name_all)
)

names(subfolder_info) <- c("Australia", "ICES", "NOAA", "All")

keyword <- c(
"biomass|b", "abundance",
"spawning biomass|sb", "spawning stock biomass|ssb", "spawning output", "spawning stock output|sso", "mature biomass", "spawners", "effective spawning output",
"spawning biomass|sb", "spawning stock biomass|ssb", "mature biomass", "spawners", "effective spawning output",
"unfished", "virgin", "initial equilibrium", "unfished equilibrium",
"recruitment",
"recruits", "recruit", "age 0 fish", "age 1 fish",
"catch", "total mortality", "harvest", "total removals",
"catch", "harvest", "total removals",
"catch per unit effort|cpue", "catch rate", "index of abundance", "catch per effort", "fishing success",
"landings", "retained catch",
"spawner per recruit|spr", "spawning potential ratio|spr",
"spawner per recruit|spr", "spawning potential ratio",
"maximum sustainable yield|msy",
"instantaneous total mortality rate|z",
"fishing mortality|f", "instantaneous fishing mortality rate", "harvest rate", "exploitation rate", "finite fishing mortality", "apical f",
"fishing mortality at maximum sustainable yield|fmsy",
"mass", "weight",
"mass",
"length composition", "length frequency", "length observation", "size frequency", "size composition",
"age composition", "age frequency", "age observation",
"projection", "forecast", "prediction",
"projection",
"sex", "gender",
"natural log of unfished recruitment|lnr0", "logr0","logr_0", "log(r0)", "r0",
"plus group"
)

xlabels <- c(
"Biomass", "Abundance",
"Spawning biomass", "Spawning stock biomass", "Spawning output", "Spawning stock output", "Mature biomass", "Spawners", "Effective spawning output",
"Spawning biomass", "Spawning stock biomass", "Mature biomass", "Spawners", "Effective spawning output",
"Unfished", "Virgin", "Initial equilibrium", "Unfished equilibrium",
"Recruitment",
"Recruits", "Recruit", "Age 0 fish", "Age 1 fish",
"Catch", "Total mortality", "Harvest", "Total removals",
"Catch", "Harvest", "Total removals",
"Catch per unit effort", "Catch rate", "Index of abundance", "Catch per effort", "Fishing success",
"Landings", "Retained catch",
"Spawner per recruit", "Spawning potential ratio",
"Maximum sustainable yield",
"Instantaneous total mortality rate",
"Fishing mortality", "Instantaneous fishing mortality rate", "Harvest rate", "Exploitation rate", "Finite fishing mortality", "Apical f",
"Fishing mortality at maximum sustainable yield",
"Mass", "Weight",
"Mass",
"Length composition", "Length frequency", "Length observation", "Size frequency", "Size composition",
"Age composition", "Age frequency", "Age observation",
"Projection", "Forecast", "Prediction",
"Projection",
"Sex", "Gender",
"Natural log of unfished recruitment", "LogR0","LogR_0", "Log(R0)", "R0",
"Plus group"
)

Expand All @@ -336,24 +339,23 @@ run_text_mining(keyword = keyword, xlabels = xlabels, working_path = working_pat

keyword <- c(
"biomass|b|abundance",
"spawning biomass|sb|spawning stock biomass|ssb|spawning output|spawning stock output|sso|mature biomass|spawners|effective spawning output",
"spawning biomass|sb|spawning stock biomass|ssb|mature biomass|spawners|effective spawning output",
"unfished|virgin|initial equilibrium|unfished equilibrium",
"recruitment",
"recruits|recruit|age 0 fish|age 1 fish",
"catch|total mortality|harvest|total removals",
"catch|harvest|total removals",
"catch per unit effort|cpue|catch rate|index of abundance|catch per effort|fishing success",
"landings|retained catch",
"spawner per recruit|spawning potential ratio|spr",
"maximum sustainable yield|msy",
"instantaneous total mortality rate|z",
"fishing mortality|f|instantaneous fishing mortality rate|harvest rate|exploitation rate|finite fishing mortality|apical f",
"fishing mortality at maximum sustainable yield|fmsy",
"mass|weight",
"mass",
"length composition|length frequency|length observation|size frequency|size composition",
"age composition|age frequency|age observation",
"projection|forecast|prediction",
"projection",
"sex|gender",
"natural log of unfished recruitment|lnr0|logr0|logr_0|log(r0)|r0",
"plus group"
)

Expand All @@ -376,7 +378,6 @@ xlabels <- c(
"Age composition",
"Projection",
"Sex",
"Natural log of unfished recruitment",
"Plus group"
)

Expand All @@ -385,25 +386,24 @@ run_text_mining(keyword = keyword, xlabels = xlabels, working_path = working_pat
subfolder_info = subfolder_info, scenario_name = "B")


jpeg(filename = here::here("TextAnalysis", "top20_wordcloud_All_mean_presence_grays_AB.jpg"),
jpeg(filename = here::here("TextAnalysis", "top19_wordcloud_All_mean_presence_grays_AB.jpg"),
width = 200, height = 120, units = "mm", res = 1200)
before_img <- rasterGrob(as.raster(jpeg::readJPEG(here::here("TextAnalysis",
"top20_wordcloud_All_mean_presence_grays_A.jpg"))),
before_img <- grid::rasterGrob(as.raster(jpeg::readJPEG(here::here("TextAnalysis",
"top19_wordcloud_All_mean_presence_grays_A.jpg"))),
interpolate = FALSE)
after_img <- rasterGrob(as.raster(jpeg::readJPEG(here::here("TextAnalysis",
"top20_wordcloud_All_mean_presence_grays_B.jpg"))),
after_img <- grid::rasterGrob(as.raster(jpeg::readJPEG(here::here("TextAnalysis",
"top19_wordcloud_All_mean_presence_grays_B.jpg"))),
interpolate = FALSE)
gridExtra::grid.arrange(before_img, after_img, ncol = 2)
dev.off()

jpeg(filename = here::here("TextAnalysis", "top20_wordcloud_All_mean_presence_black_AB.jpg"),
jpeg(filename = here::here("TextAnalysis", "top19_wordcloud_All_mean_presence_black_AB.jpg"),
width = 200, height = 120, units = "mm", res = 1200)
before_img <- rasterGrob(as.raster(jpeg::readJPEG(here::here("TextAnalysis",
"top20_wordcloud_All_mean_presence_black_A.jpg"))),
before_img <- grid::rasterGrob(as.raster(jpeg::readJPEG(here::here("TextAnalysis",
"top19_wordcloud_All_mean_presence_black_A.jpg"))),
interpolate = FALSE)
after_img <- rasterGrob(as.raster(jpeg::readJPEG(here::here("TextAnalysis",
"top20_wordcloud_All_mean_presence_black_B.jpg"))),
after_img <- grid::rasterGrob(as.raster(jpeg::readJPEG(here::here("TextAnalysis",
"top19_wordcloud_All_mean_presence_black_B.jpg"))),
interpolate = FALSE)
gridExtra::grid.arrange(before_img, after_img, ncol = 2)
dev.off()

Binary file added TextAnalysis/top19_barplot_All_A.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TextAnalysis/top19_barplot_All_B.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TextAnalysis/top19_barplot_Australia_A.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TextAnalysis/top19_barplot_Australia_B.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TextAnalysis/top19_barplot_ICES_A.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TextAnalysis/top19_barplot_ICES_B.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TextAnalysis/top19_barplot_NOAA_A.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TextAnalysis/top19_barplot_NOAA_B.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5501818

Please sign in to comment.