R/DensityPlot.R

Defines functions density_plot

Documented in density_plot

#' @title Density Plot Generator
#'
#' @param  dataset -- Data Frame to evaluate
#' @param  group -- Column in data (the variable) that you wish to look at.
#' @param  value --  Is value in the column ( the variable) you wish to create a density plot
#' @param  plot --  the parameter that you wish to use for the density plot
#' @param  Bandwith -- width of smothting in kernal density estimation
#'
#' @import dplyr
#' @import ggplot2
#' @import lazyeval
#'
#' @export

density_plot <- function(dataset, group, value, y, ylimit, bandwidth=1){



  #filter the data by the set by the goup (variable) that is equal to value choosen
  if(value == ""){

  }else{
    #filter the data by the set by the goup (variable) that is equal to value choosen
    filter_criteria <- interp(~y == x, .values=list(y = as.name(group), x = value))
    dataset <- dataset %>% filter_(filter_criteria)

  }



  #remove blank entries from the dataset
  filter_criteria <- interp(~y != x, .values=list(y = as.name(y), x = ""))
  dataset <- dataset %>% filter_(filter_criteria)
  filter_criteria <- interp(~y <= x, .values=list(y = as.name(y), x = as.numeric(ylimit)))
  dataset <- dataset %>% filter_(filter_criteria)


  p <-  ggplot(dataset, aes_string(x = y, fill = group)) +
          geom_density(bw=bandwidth)

  return(p)

}
AshMSTAT/DSTools documentation built on May 20, 2019, 8:29 a.m.