inst/app-visualize/helper/unibar.R

library(highcharter)
library(dplyr)
library(magrittr)

highbar <- function(data, column, title = '', name = '', horizontal = FALSE) {
  
  da <- data %>%
    select_(column) %>%
    pull(1) %>%
    as.factor()
  
  lev <- da %>%
    levels()
  
  tab <- da %>%
    table() %>%
    as.vector()
  
  if (horizontal) {
    bartype <- 'bar'
  } else {
    bartype <- 'column'
  }
  
  highchart() %>%
    hc_chart(type = bartype) %>%
    hc_title(text = title) %>%
    hc_xAxis(categories = lev) %>%
    hc_add_series(data = tab,
                  name = name)
  
}

highbar(mtcars, 'cyl', horizontal = TRUE)
data <- mtcars
column <- 'cyl'

Try the xplorerr package in your browser

Any scripts or data that you put into this service are public.

xplorerr documentation built on Feb. 28, 2019, 5:05 p.m.