Skip to content

Commit

Permalink
adding hcwaffle, hcbar, hcpie, hchist, hcboxplot, #99
Browse files Browse the repository at this point in the history
  • Loading branch information
jbkunst committed May 17, 2016
1 parent 7708660 commit 4e736cb
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 45 deletions.
6 changes: 5 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ export(hc_tooltip)
export(hc_xAxis)
export(hc_yAxis)
export(hc_yAxis_multiples)
export(hcbar)
export(hcboxplot)
export(hchart)
export(hchart_waffle)
export(hchist)
export(hcpie)
export(hcwaffle)
export(hex_to_rgba)
export(highchart)
export(highchart2)
Expand Down
63 changes: 53 additions & 10 deletions R/hchart_waffle.R → R/hc-charts.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
#' Function to make a bar chart
#'
#' @param x A character o factor vector.
#' @param ... Aditional shared arguments for the data series (http://api.highcharts.com/highcharts#series).
#' @export
hcbar <- function(x, ...) {
stopifnot(is.character(x) | is.factor(x))
hchart(x, ...)
}

#' Function to make a pie chart
#' @param x A character o factor vector.
#' @param ... Aditional shared arguments for the data series (http://api.highcharts.com/highcharts#series).
#' @export
hcpie <- function(x, ...) {
stopifnot(is.character(x) | is.factor(x))
hchart(x, type = "pie", ...)
}

#' Function to make an histogram
#' @param x A numeric vector.
#' @param ... Aditional shared arguments for the data series (http://api.highcharts.com/highcharts#series).
#' @export
hchist <- function(x, ...) {
stopifnot(is.numeric(x))
hchart(x, ...)
}

#' Function to make a boxplot
#' @param x A numeric vector.
#' @param by A character vector same length of \code{x}
#' @param ... Aditional shared arguments for the data series (http://api.highcharts.com/highcharts#series).
#' @param outliers A boolean value to show or not the outliers
#' @export
hcboxplot <- function(x, by = NULL, outliers = TRUE, ...) {
stopifnot(is.numeric(x))
if (is.null(by))
hc_add_series_boxplot(highchart(), x, outliers = outliers, ...)
else
hc_add_series_boxplot(highchart(), x, by = by, outliers = outliers, ...)


hchart(x, ...)
}

#' Function to create waffle charts
#'
#' @param labels A character vector
Expand All @@ -8,18 +53,18 @@
#'
#' @examples
#'
#' hchart_waffle(c("nice", "good"), c(10, 20))
#' hcwaffle(c("nice", "good"), c(10, 20))
#'
#' hchart_waffle(c("nice", "good"), c(10, 20), size = 10)
#' hcwaffle(c("nice", "good"), c(10, 20), size = 10)
#'
#' hchart_waffle(c("nice", "good"), c(100, 200), icons = "child")
#' hcwaffle(c("nice", "good"), c(100, 200), icons = "child")
#'
#' hchart_waffle(c("car", "truck", "plane"), c(50, 20, 10), icons = c("car", "truck", "plane"))
#' hcwaffle(c("car", "truck", "plane"), c(50, 20, 10), icons = c("car", "truck", "plane"))
#'
#' @importFrom dplyr ungroup arrange desc group_by_
#' @export
hchart_waffle <- function(labels, counts, rows = NULL, icons = NULL, size = 4){

hcwaffle <- function(labels, counts, rows = NULL, icons = NULL, size = 4){
# library(dplyr);library(purrr)
# data(diamonds, package = "ggplot2")
# cnts <- count(diamonds, cut) %>%
Expand All @@ -29,7 +74,7 @@ hchart_waffle <- function(labels, counts, rows = NULL, icons = NULL, size = 4){
# labels <- cnts$cut
# counts <- cnts$n
# size <- 4; icon <- "diamond"

assertthat::assert_that(length(counts) == length(labels))

hc <- highchart()
Expand Down Expand Up @@ -70,7 +115,7 @@ hchart_waffle <- function(labels, counts, rows = NULL, icons = NULL, size = 4){
ds <- ds %>%
left_join(dsmrk, by = "name") %>%
mutate(icon = fa_icon(icons))

}

hc <- hc %>%
Expand All @@ -80,8 +125,6 @@ hchart_waffle <- function(labels, counts, rows = NULL, icons = NULL, size = 4){
hc_tooltip(pointFormat = "{point.series.options.counts}") %>%
hc_add_theme(hc_theme_null())


hc


}
17 changes: 17 additions & 0 deletions man/hcbar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions man/hcboxplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 0 additions & 34 deletions man/hchart_waffle.Rd

This file was deleted.

17 changes: 17 additions & 0 deletions man/hchist.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/hcpie.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions man/hcwaffle.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4e736cb

Please sign in to comment.