inst/app-visualize/helper/bibar.R

bibar <- function(data, x, y, horizontal = FALSE, stacked = FALSE) {

	da <- data %>%
	  select_(x, y) %>%
	  table()

	xcat <- da %>%
	  rownames() %>%
	  as.numeric()
	  
	types <- da %>%
    ncol() %>%
    seq_len()

  if (horizontal) {

    h <- highchart() %>%
		  hc_chart(type = 'bar') %>%
		  hc_xAxis(categories = xcat) 

		if (stacked) {

      h <- h %>%
        hc_plotOptions(bar = list(stacking = 'normal'))

		}

  } else {

		h <- highchart() %>%
		  hc_chart(type = 'column') %>%
		  hc_xAxis(categories = xcat) 

		if (stacked) {

      h <- h %>%
        hc_plotOptions(column = list(stacking = 'normal'))  	

		}

  }


	for (i in types) {
	  h <- h %>%
	    hc_add_series(data = da[i, ] %>% as.vector()) 
	}

	h

}

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.