R/bvi_plot.R

#' Biological Value Index grapher
#' 
#' @description Creates a graph to graphicaly represent the score matrix of the Biological Value Index.
#' 
#' @param bvi_scores An object of class data.frame generated generated by bvi()
#' 
#' @seealso bvi
#' 
#' @author Villasenor-Derbez, J.C.
#' 
#' @export
#' 

bvi_plot=function(bvi_scores){
  library(ggplot2)
  library(dplyr)
  library(tidyr)
  
  total=colSums(bvi_scores[2:(length(bvi_scores)-2)])
  total=matrix(total, nrow=length(bvi_scores)-3, ncol=length(bvi_scores$spp))
  
  bvi_scores[2:(length(bvi_scores)-2)]=bvi_scores[2:(length(bvi_scores)-2)]/total
  
  bvi_scores=bvi_scores%>%
    select(1:(length(bvi_scores)-2))%>%
    gather(sample, score, -1)
  
  ggplot(bvi_scores, aes(x=sample, y=score, fill=spp))+
    geom_bar(stat="identity", color="black")+
    scale_y_continuous(labels = scales::percent)
  
}
bvindex/Rbvi documentation built on May 13, 2019, 9:05 a.m.