diff --git a/DESCRIPTION b/DESCRIPTION index 2061ead3..f2100a14 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -74,6 +74,10 @@ Collate: tuneParams_helpers.R getYieldVsFcurve.R plots.R + comparedietmatrix.R + guildplot.R + plotSpeciesWithTimeRange.R + yieldplottingfunctions.R Encoding: UTF-8 RoxygenNote: 7.3.2 Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index 53a0fae3..1405e43b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,8 +2,10 @@ export(adjustBackgroundSpecies) export(alignResource) +export(comparedietmatrix) export(distanceSSLogYield) export(getYieldVsF) +export(guildplot) export(markBackground) export(matchYield) export(plotBiomassFlux) @@ -15,6 +17,7 @@ export(plotEnergyBudget) export(plotNumberVsSpecies) export(plotResourceLevel) export(plotResourcePred) +export(plotSpeciesWithTimeRange) export(plotSpectra2) export(plotSpectraRelative) export(plotYieldRelative) diff --git a/R/comparedietmatrix.R b/R/comparedietmatrix.R new file mode 100644 index 00000000..74db2527 --- /dev/null +++ b/R/comparedietmatrix.R @@ -0,0 +1,74 @@ +#'I am not sure if this code works as intended. It appears so, as I have checked it, +#'but the results are not what it is expected. +#' +#'I will also need to see if edge cases, where the timerange is 1:1, work. + + + +#This function plots the diet matrix from the mizersim objects. +#' Plot Relative Diet Proportion of each Prey/Predator +#' +#' This function takes two mizerSim objects and calculates the relative +#' change in the proportion of a given prey species in a predators diet. This +#' is done for every prey/predator in the model. +#' +#' @param harvested A mizerSim object +#' @param unharvested A mizerSim object - to compare to. +#' @param chosentime The year range to plot (example 1:2). +#' +#' @return A ggplot object of a matrix of predator species on the X axis, +#' prey species on the Y axis. The colour of the box indicates the change +#' of the proportion in the predator's diet of the given prey species. +#' +#' +#' @examples +#' harvested <- project(NS_params) +#' unharvested <- project(NS_params) +#' comparedietmatrix(harvested, unharvested, 1:2) +#' +#' @export +comparedietmatrix <- function(unharvestedprojection, harvestedprojection, timerange){ + + #THE TIMERANGE SHOULD BE X:Y + dietunharv <- getDiet(unharvestedprojection@params, + n = apply(unharvestedprojection@n[timerange,,], c(2, 3), mean), + n_pp = apply(unharvestedprojection@n_pp[timerange,], 2, mean), + n_other = apply(unharvestedprojection@n_other[timerange,], 2, mean), + proportion = TRUE) %>% + as.table()%>% + as.data.frame()%>% + group_by(predator, prey)%>% + summarise(Proportion=mean(Freq)) + + dietharv <- getDiet(unharvestedprojection@params, + n = apply(unharvestedprojection@n[timerange,,], c(2, 3), mean), + n_pp = apply(unharvestedprojection@n_pp[timerange,], 2, mean), + n_other = apply(unharvestedprojection@n_other[timerange,], 2, mean), + proportion = TRUE) %>% + as.table()%>% + as.data.frame()%>% + group_by(predator, prey)%>% + summarise(Proportion=mean(Freq)) + + joindiet <- left_join(dietharv, dietunharv, by = c("prey", "predator"))%>% + mutate(Difference = ((Proportion.x - Proportion.y) / Proportion.y) * 100) %>% # Calculate percentage change + select(predator, prey, Difference)%>% + filter(!predator %in% c("2", "4", "6", "8", "16", "17", "18", "19", "20", "Resource"), + !prey %in% c("2", "4", "6", "8", "16", "17", "18", "19", "20", "Resource")) + + dietplot <- ggplot(joindiet, aes(x = predator, y = prey, fill = Difference)) + + geom_tile() + + scale_fill_gradient2() + + labs(x = "Predator", + y = "Prey", + fill = "Difference") + + theme_minimal()+ + theme(axis.text.x = element_text(angle = 45, hjust = 1,size = 14), + axis.text.y = element_text(size = 14), + axis.title.x = element_text(size = 16), + axis.title.y = element_text(size = 16)) + + + return(dietplot) + +} diff --git a/R/guildplot.R b/R/guildplot.R new file mode 100644 index 00000000..7ab171ce --- /dev/null +++ b/R/guildplot.R @@ -0,0 +1,151 @@ + +#' Plot Guild Relative Change Across Timescales +#' +#' This function takes two mizerSim objects and calculates the relative % +#' change in each given feeding guilde in the chosen year, short term (1/2 of the +#' chosen year) and the long term (2x the chosen year) +#' This function requires a dataframe in the environment titled guildparams - this dataframe should have +#' a column for minw (minimum weight of guild), maxw (maxmimum weight), guild ( +#' the guild for the given weight), and a column for the species (which matches the mizersim species). +#' The mizerSim objects must also have a tmax of 2 * year2. +#' +#' +#' @param harvested A mizerSim object +#' @param unharvested A mizerSim object - to compare to. +#' @param year1 The lower year to plot in the range +#' @param year2 The higher year to plot in the range +#' +#' @return A ggplot object that plots 3 bars per species - in the short, +#' chosen and long time - it plots the relative biomass of each feeding guild +#' in comparison to the unharvested. +#' +#' +#' @examples +#' harvested <- project(NS_params) +#' unharvested <- project(NS_params) +#' guildplot(harvested, unharvested, 1, 2) +#' +#' @export +guildplot <- function(harvestedprojection, unharvestedprojection, year1, year2) { + + harvestedshort <- plotSpectra(harvestedprojection, time_range = max(1, round(year1 * (1/2))):max(1, round(year2 * (1/2))), return_data = TRUE) + harvested <- plotSpectra(harvestedprojection, time_range = year1:year2, return_data = TRUE) + harvestedlong <- plotSpectra(harvestedprojection, time_range = (year1 * 2):(year2 * 2), return_data = TRUE) + + unharvestedshort <- plotSpectra(unharvestedprojection, time_range = max(1, round(year1 * (1/2))):max(1, round(year2 * (1/2))), return_data = TRUE) + unharvested <- plotSpectra(unharvestedprojection, time_range = year1:year2, return_data = TRUE) + unharvestedlong <- plotSpectra(unharvestedprojection, time_range = (year1 * 2):(year2 * 2), return_data = TRUE) + + process_guilds <- function(mizerprojection) { + + + assign_guild <- function(data, rules) { + data <- data %>% + mutate(Guild = NA_character_) # Initialize Guild column with NA + + # Loop through each rule in the rules dataframe + for (i in 1:nrow(rules)) { + data <- data %>% + mutate( + #THIS CODE ASSUMES THAT ANYTHING UNDER W 0.05 IS PLANKTIVOROUS, AS IT IS VERY SMALL + Guild = ifelse(w < 0.05, "Plank", + ifelse( + is.na(Guild) & w >= rules$minw[i] & w < rules$maxw[i], + rules$Feeding.guild[i], Guild) + ) + ) + } + + return(data) + } + + + mizerprojection <- mizerprojection %>% + group_by(Species) %>% + group_modify(~ { + species_data <- .x + + species_name <- unique(species_data$Legend) + + species_rules <- guildparams %>% + filter(Species == species_name) + + if (nrow(species_rules) == 0) { + return(species_data) + } + + assign_guild(species_data, species_rules) + + }) %>% + ungroup() %>% + #this next step takes out anything without an assigned guild, but you might not choose to do this + #and then you can have a column of the change in biomass of species/sizes that we do not have guild rules for + #this would be useful to observe where the biomass change is going, but would be confusing to interpret and explain. + #(as its a possibility that all 3 guilds show a negative decrease, which looks like a decrease in biomass, + #but may just be due to other sizes/species taking this biomass) + drop_na(Guild)%>% + group_by(Guild) %>% + summarise(value = mean(value)) + + return(mizerprojection) + + } + + #for the harvested - + guildsshort <- process_guilds(harvestedshort) + guilds <- process_guilds(harvested) + guildslong <- process_guilds(harvestedlong) + #for the unharvested - + unguildsshort <- process_guilds(unharvestedshort) + unguilds <- process_guilds(unharvested) + unguildslong <- process_guilds(unharvestedlong) + + #now joining them together + guildsshort$time <- "short" + guilds$time <- "chosen" + guildslong$time <- "long" + unguildsshort$time <- "short" + unguilds$time <- "chosen" + unguildslong$time <- "long" + + joinedguilds <- bind_rows(guildsshort, guilds, guildslong) %>% + group_by(Guild, time) %>% + summarise(value = sum(value, na.rm = TRUE), .groups = "drop") + + unjoinedguilds <- bind_rows(unguildsshort, unguilds, unguildslong) %>% + group_by(Guild, time) %>% + summarise(value = sum(value, na.rm = TRUE), .groups = "drop") + + joinedguilds <- joinedguilds%>% + full_join(unjoinedguilds, by = c("Guild", "time"),relationship = "many-to-many") %>% + mutate(percentage_diff = ((value.x-value.y)/value.y))%>% + select(Guild, time, percentage_diff) + + #this sets the colours correctly + joinedguilds$time <- factor(joinedguilds$time, levels = c("short", "chosen", "long")) + joinedguilds$fill_group <- interaction(joinedguilds$percentage_diff >= 0, joinedguilds$time) + + #plotting + ggplot(joinedguilds, aes(x = Guild, y = percentage_diff, fill = fill_group)) + + geom_bar(stat = "identity", position = position_dodge(width = 0.9)) + + scale_fill_manual(values = c( + "FALSE.short" = "#E76F51", + "FALSE.chosen" = "#E98C6B", + "FALSE.long" = "#F2A488", + "TRUE.short" = "#2FA4E7", + "TRUE.chosen" = "#2FA4E7cc", + "TRUE.long" = "#2FA4E799" + )) + + labs(title = "Percentage Change by Guild", + x = "Guild", + y = "Percentage Change") + + theme_minimal() + + theme( + axis.text.x = element_text(size = 14, angle = 90, hjust = 1, vjust = 0.5), + axis.text.y = element_text(size = 14), + legend.position = "none", + axis.title.x = element_text(size = 16), + axis.title.y = element_text(size = 16) + ) + +} diff --git a/R/plotSpeciesWithTimeRange.R b/R/plotSpeciesWithTimeRange.R new file mode 100644 index 00000000..a3cf958c --- /dev/null +++ b/R/plotSpeciesWithTimeRange.R @@ -0,0 +1,143 @@ +#This function plots the species plot - which the change in species for a given +#year, and also for 2x in future and 1/2 year in the past. + + +#' Plot MizerSim Relative Biomass per Species Across Varying Timescales +#' +#' This function takes two mizerSim objects and calculates the relative % +#' change in each given species in the chosen year, short term (1/2 of the +#' chosen year) and the long term (2x the chosen year). The mizerSim +#' objects must have tmax = 2 * chosentime2. +#' +#' @param harvested A mizerSim object +#' @param unharvested A mizerSim object - to compare to. +#' @param chosentime1 The first year to plot in the range +#' @param chosentime2 The last year to plot in the range +#' +#' @return A ggplot object that plots 3 bars per species - in the short, +#' chosen and long time - it plots the relative biomass of each species in +#' comparison to the unharvested. +#' +#' +#' @examples +#' harvested <- project(NS_params) +#' unharvested <- project(NS_params) +#' plotSpeciesWithTimeRange(harvested, unharvested, 1, 2) +#' +#' @export +plotSpeciesWithTimeRange <- function(harvestedprojection, unharvestedprojection, chosentime1, chosentime2) { + + #get the biomass of the species + unharvestedbio <- getBiomass(unharvestedprojection) %>% + .[chosentime1:chosentime2, ] %>% + melt() %>% + group_by(sp) %>% + summarize(value = mean(value, na.rm = TRUE)) + + harvestedbio <- getBiomass(harvestedprojection) %>% + .[chosentime1:chosentime2, ] %>% + melt() %>% + group_by(sp) %>% + summarize(value = mean(value, na.rm = TRUE)) + + #calculate percentage change in species in the chosen year + percentage_diff <- harvestedbio %>% + left_join(unharvestedbio, by = "sp") %>% + mutate(percentage_diff = ((value.x - value.y) / value.y) * 100, + Species = sp) %>% + select(Species, percentage_diff) %>% + filter(!Species %in% c("2", "4", "6", "8", "16", "17", "18", "19", "20", "Resource"))%>% + mutate(class = "chosen") + + calculate_biomass_triples <- function(unharvestedprojection, harvestedprojection, year1, year2) { + + # Calculate unharvested biomass at different time points + unharvestedbiotriple <- getBiomass(unharvestedprojection) + + #the range has to be 1-2, becuase if it is 1-1 it messes with the way the data is formatted. + #i have also used ceiling here, because using round means they round to nearest even number, so some cases (11:13) + #end up as 6:6 for the lowbiotrip - this does not work for the code format. + lowunbiotrip <- unharvestedbiotriple[max(1, ceiling(year1 * (1/2))):max(2, ceiling(year2 * (1/2))), ] %>% + melt() %>% + group_by(sp) %>% + summarize(value = mean(value, na.rm = TRUE)) + + highunbiotrip <- unharvestedbiotriple[(year1 * 2):(year2 * 2), ] %>% + melt() %>% + group_by(sp) %>% + summarize(value = mean(value, na.rm = TRUE)) + + # Calculate harvested biomass at different time points + harvestedbiotriple <- getBiomass(harvestedprojection) + + lowbiotrip <- harvestedbiotriple[max(1, ceiling(year1 * (1/2))):max(2, ceiling(year2 * (1/2))),] %>% + melt() %>% + group_by(sp) %>% + summarize(value = mean(value, na.rm = TRUE)) + + highbiotrip <- harvestedbiotriple[(year1 * 2):(year2 * 2), ] %>% + melt() %>% + group_by(sp) %>% + summarize(value = mean(value, na.rm = TRUE)) + + # Return the results as a list + list( + lowunbiotrip, + highunbiotrip, + lowbiotrip, + highbiotrip + ) + } + + #calculate percentage change in other years + biorange <- calculate_biomass_triples(unharvestedprojection, harvestedprojection, chosentime1, chosentime2) + + #percentage_difflow <- percentdiff(biorange[[3]], biorange[[1]]) + #percentage_difflow$class <- "short" + + percentage_difflow <- biorange[[3]] %>% + left_join(biorange[[1]], by = "sp") %>% + mutate(percentage_diff = ((value.x - value.y) / value.y) * 100, + Species = sp) %>% + select(Species, percentage_diff) %>% + filter(!Species %in% c("2", "4", "6", "8", "16", "17", "18", "19", "20", "Resource"))%>% + mutate(class = "short") + + #percentage_diffhigh <- percentdiff(biorange[[4]], biorange[[2]]) + #percentage_diffhigh$class <- "long" + + percentage_diffhigh <- biorange[[4]] %>% + left_join(biorange[[2]], by = "sp") %>% + mutate(percentage_diff = ((value.x - value.y) / value.y) * 100, + Species = sp) %>% + select(Species, percentage_diff) %>% + filter(!Species %in% c("2", "4", "6", "8", "16", "17", "18", "19", "20", "Resource"))%>% + mutate(class = "long") + + percentage_diff <- rbind(percentage_difflow, percentage_diff, percentage_diffhigh) + + #now plot them together - the first lines sort out the colors of the bars + percentage_diff$class <- factor(percentage_diff$class, levels = c("short", "chosen", "long")) + percentage_diff$fill_group <- interaction(percentage_diff$percentage_diff >= 0, percentage_diff$class) + + ggplot(percentage_diff, aes(x = Species, y = percentage_diff, fill = fill_group)) + + geom_bar(stat = "identity", position = position_dodge(width = 0.9)) + + geom_hline(yintercept = 0, color = "grey", linetype = "dashed", size = 0.5)+ + labs(x = "Species", y = "Percentage Change") + + scale_fill_manual(values = c( + "FALSE.short" = "#E76F51", + "FALSE.chosen" = "#E98C6B", + "FALSE.long" = "#F2A488", + "TRUE.short" = "#2FA4E7", + "TRUE.chosen" = "#2FA4E7cc", + "TRUE.long" = "#2FA4E799" + )) + + theme_minimal() + + theme( + axis.text.x = element_text(size = 16, angle = 90, hjust = 1, vjust = 0.5), + axis.text.y = element_text(size = 14), + legend.position = "none", + axis.title.x = element_text(size = 16), + axis.title.y = element_text(size = 16) + ) +} diff --git a/R/yieldplottingfunctions.R b/R/yieldplottingfunctions.R new file mode 100644 index 00000000..9cd5750b --- /dev/null +++ b/R/yieldplottingfunctions.R @@ -0,0 +1,131 @@ + +#plotype can be "fleet" - plots two pie charts for the harvested and unharvested mizerSims. +#each pie chart show the % composition of the total yield from each fleet (or gears) +#plottype = "species" - plots two pie charts for the harvested and unharvested mizerSims. +#each pie chart shows the % composition of the total yield from each species +#plottype = "singlefleet" - plots a pie chart for each gear and each mizersim object +#each plot shows the % species composition of the yield of a given gear. + +yieldplottingfunctions <- function(harvested, unharvested, timerange1, timerange2, plottype) { + + if (plottype == "fleet") { + + #getting yield per gear then reformating to work with rest of the code, + #plus subsetting by year + + harv <- as.data.frame(as.table(getYieldGear(harvested)[c(timerange1, timerange2),,]))%>% + group_by(gear)%>% + summarise(value=mean(Freq))%>% + subset(value>0) + + unharv <-as.data.frame(as.table(getYieldGear(unharvested)[c(timerange1, timerange2),,]))%>% + group_by(gear)%>% + summarise(value=mean(Freq))%>% + subset(value>0) + + fig <- plot_ly() + fig <- fig %>% add_pie(data = harv, labels = ~gear, values = ~value, + name = "harv", domain = list(row = 0, column = 0), + title = "Changed Strategy Yield") + fig <- fig %>% add_pie(data = unharv, labels = ~gear, values = ~value, + name = "unharv", domain = list(row = 0, column = 1), + title = "Current Strategy Yield") + + fig <- fig %>% layout(showlegend = T, + grid = list(rows = 1, columns = 2), + xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE), + yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE)) + fig + + } else if (plottype == "species") { + + harv <- as.data.frame(as.table(getYield(harvested)[c(timerange1, timerange2),]))%>% + group_by(sp)%>% + summarise(value=mean(Freq))%>% + rename(gear = sp)%>% + subset(value>0) + + unharv <- as.data.frame(as.table(getYield(unharvested)[c(timerange1, timerange2),]))%>% + group_by(sp)%>% + summarise(value=mean(Freq))%>% + rename(gear = sp)%>% + subset(value>0) + + fig <- plot_ly() + fig <- fig %>% add_pie(data = harv, labels = ~gear, values = ~value, + name = "harv", domain = list(row = 0, column = 0), + title = "Changed Strategy Yield") + fig <- fig %>% add_pie(data = unharv, labels = ~gear, values = ~value, + name = "unharv", domain = list(row = 0, column = 1), + title = "Current Strategy Yield") + + + fig <- fig %>% layout(showlegend = T, + grid = list(rows = 1, columns = 2), + xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE), + yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE)) + return(fig) + + } else if (plottype == "singlefleet") { + + harv <- as.data.frame(as.table(getYieldGear(harvested)[c(timerange1, timerange2),,])) + unharv <-as.data.frame(as.table(getYieldGear(unharvested)[c(timerange1, timerange2),,])) + + harv <- split(harv, harv$gear) + unharv <- split(unharv, unharv$gear) + + fig <- plot_ly() + + for (i in seq_along(harv)) { + + gear_name <- names(harv)[i] + + #this is necessary as for some reason the survey gear is plotted differently, which messes with the layout. + if (gear_name == "survey") { + next + } + + averaged_data <- harv[[gear_name]] %>% + group_by(sp) %>% + summarise(value = mean(Freq)) + colnames(averaged_data) <- c("gear", "value") + + fig <- fig %>% add_pie(data = averaged_data, labels = ~gear, values = ~value, + title = list(text = paste("Changed", gear_name)), + textinfo = "none", + name = gear_name, domain = list(row = 0, column = i)) + + } + for (i in seq_along(unharv)) { + + gear_name <- names(unharv)[i] + + if (gear_name == "survey") { + next + } + + averaged_data <- unharv[[gear_name]] %>% + group_by(sp) %>% + summarise(value = mean(Freq)) + colnames(averaged_data) <- c("gear", "value") + + + fig <- fig %>% add_pie(data = averaged_data, labels = ~gear, values = ~value, + title = gear_name, + textinfo = "none", + name = gear_name, domain = list(row = 1, column = i)) + + } + + fig <- fig %>% layout(showlegend = T, + grid=list(rows=2, columns=length(harv)), + xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE), + yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE)) + fig + + } else { + + stop("Invalid plot type specified") + } + +} \ No newline at end of file diff --git a/man/comparedietmatrix.Rd b/man/comparedietmatrix.Rd new file mode 100644 index 00000000..a49c0c2d --- /dev/null +++ b/man/comparedietmatrix.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/comparedietmatrix.R +\name{comparedietmatrix} +\alias{comparedietmatrix} +\title{I am not sure if this code works as intended. It appears so, as I have checked it, +but the results are not what it is expected.} +\usage{ +comparedietmatrix(unharvestedprojection, harvestedprojection, timerange) +} +\arguments{ +\item{harvested}{A mizerSim object} + +\item{unharvested}{A mizerSim object - to compare to.} + +\item{chosentime}{The year range to plot (example 1:2).} +} +\value{ +A ggplot object of a matrix of predator species on the X axis, +prey species on the Y axis. The colour of the box indicates the change +of the proportion in the predator's diet of the given prey species. +} +\description{ +I will also need to see if edge cases, where the timerange is 1:1, work. +Plot Relative Diet Proportion of each Prey/Predator +} +\details{ +This function takes two mizerSim objects and calculates the relative +change in the proportion of a given prey species in a predators diet. This +is done for every prey/predator in the model. +} +\examples{ +harvested <- getBiomass(NS_sim) +unharvested <- getBiomass(NS_sim) +comparedietmatrix(harvested, unharvested, 5) + +} diff --git a/man/guildplot.Rd b/man/guildplot.Rd new file mode 100644 index 00000000..c585b436 --- /dev/null +++ b/man/guildplot.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/guildplot.R +\name{guildplot} +\alias{guildplot} +\title{Plot Guild Relative Change Across Timescales} +\usage{ +guildplot(harvestedprojection, unharvestedprojection, year1, year2) +} +\arguments{ +\item{year1}{The lower year to plot in the range} + +\item{year2}{The higher year to plot in the range} + +\item{harvested}{A mizerSim object} + +\item{unharvested}{A mizerSim object - to compare to.} +} +\value{ +A ggplot object that plots 3 bars per species - in the short, +chosen and long time - it plots the relative biomass of each feeding guild +in comparison to the unharvested. +} +\description{ +This function takes two mizerSim objects and calculates the relative \% +change in each given feeding guilde in the chosen year, short term (1/2 of the +chosen year) and the long term (2x the chosen year) +This function requires a dataframe in the environment titled guildparams - this dataframe should have +a column for minw (minimum weight of guild), maxw (maxmimum weight), guild ( +the guild for the given weight), and a column for the species (which matches the mizersim species). +The mizerSim objects must also have a tmax of 2 * year2. +} +\examples{ +harvested <- getBiomass(NS_sim) +unharvested <- getBiomass(NS_sim) +guildplot(harvested, unharvested, 1, 2) + +} diff --git a/man/plotSpeciesWithTimeRange.Rd b/man/plotSpeciesWithTimeRange.Rd new file mode 100644 index 00000000..ee13cf38 --- /dev/null +++ b/man/plotSpeciesWithTimeRange.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotSpeciesWithTimeRange.R +\name{plotSpeciesWithTimeRange} +\alias{plotSpeciesWithTimeRange} +\title{Plot MizerSim Relative Biomass per Species Across Varying Timescales} +\usage{ +plotSpeciesWithTimeRange( + harvestedprojection, + unharvestedprojection, + chosentime1, + chosentime2 +) +} +\arguments{ +\item{harvested}{A mizerSim object} + +\item{unharvested}{A mizerSim object - to compare to.} + +\item{chosentime}{The year to plot} +} +\value{ +A ggplot object that plots 3 bars per species - in the short, +chosen and long time - it plots the relative biomass of each species in +comparison to the unharvested. +} +\description{ +This function takes two mizerSim objects and calculates the relative \% +change in each given species in the chosen year, short term (1/2 of the +chosen year) and the long term (2x the chosen year). The mizerSim +objects must have tmax = 2 * chosentime2. +} +\examples{ +harvested <- getBiomass(NS_sim) +unharvested <- getBiomass(NS_sim) +plotSpeciesWithTimeRange(harvested, unharvested, 1, 2) + +}