R/get-vis.R

Defines functions get_vis

Documented in get_vis

#' create a group-aware visualisation
#'
#' @param .data the standard dataframe, modified so the last column
#'     is the output of some insight function (eg. output from
#'     term_freq)
#'
#' @param vis character name of visualisation function
#'
#' @param col character name of the column to get insight from
#'
#' @param facet_by character name of the column to facet by
#'
#' @param scale_fixed force scales to be fixed in a facet
#' 
#' @param ncol number of columns for facet wrap
#'  
#' @param ... additional arguments to the visualisation
#'
#' @export
get_vis <- function(.data, vis, col, facet_by="", scale_fixed = TRUE, ncol = 3, ...){
    vistable <- list("Page View" = struct_pageview,
                     "Time Series" = struct_time_series,
                     "Bar" = score_barplot,
                     "Density" = dist_density,
                     "Histogram" = dist_hist,
                     "Word Cloud" = score_wordcloud)
    y <- dplyr::sym(col)
    chart <- vistable[[vis]](.data, !! y, ...)
    if (shiny::isTruthy(facet_by)){
        facet_name <- dplyr::sym(facet_by)
        q_facet_name <- dplyr::enquo(facet_name)
        return(chart + ggplot2::facet_wrap(ggplot2::vars(!! q_facet_name),
                  scales = ifelse(vis == "struct_pageview" | scale_fixed,
                                                               "fixed",
                                                               "free"), ncol = ncol))
        }

    else {
        return(chart)
    }
}
jcai849/iNZightTA documentation built on Dec. 2, 2020, 6:59 a.m.