# WARNING - Generated by {fusen} from dev/flat_plots.Rmd: do not edit by hand # nolint: line_length_linter.

#' Plot inflow concentration
#' 
#' Violin plot of inflow concentration according to pathogen simulated
#' @param scenario data.frame with inflow_concentration column obtained from inflow_concentration function
#' @import ggplot2
#' @importFrom purrr map
#' @return plot
#' 
#' @export
#' @examples
#' scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre"))
#' scenario_with_inflow <- inflow_concentration(scenario = scenario_test,
#'  pathogenName = c("Campylobacter jejuni", "Norovirus"))
#' plot_inflow(scenario_with_inflow)
plot_inflow <- function(scenario){
  pathoName <- map(.x = scenario$inflow_concentration, .f = ~.x$events$PathogenName)
  pathoGroup <- map(.x = scenario$inflow_concentration, .f = ~.x$events$PathogenGroup)
  inflow_concentration <- map(.x = scenario$inflow_concentration, .f = ~.x$events$inflow)

  plot_data <- data.frame(PathogenName = unlist(pathoName),
                          PathogenGroup = unlist(pathoGroup),
                          inflow = unlist(inflow_concentration))
  
  fill_color <- c("Bacteria" = "palegreen3", 
                  "Viruses"  = "orchid", 
                  "Protozoa" = "darkorange")
  
  plot <- ggplot(
          data = plot_data,
          mapping = aes(x = PathogenName,
                                 y = inflow / 10,
                                 fill = PathogenGroup)
       ) +
    geom_violin(trim = FALSE,
                         alpha = 0.7,
                         colour = "black") +
    scale_y_log10() +
    scale_fill_manual(values = fill_color,
                               name = "Pathogen group") +
    theme_minimal() +
    labs(
      x = "Names of the pathogen simulated",
      y = "log/100mL"
    )
  
  return(plot)
}
