diff --git a/NAMESPACE b/NAMESPACE index 67aac4ba..7fa603d1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/hchart_waffle.R b/R/hc-charts.R similarity index 51% rename from R/hchart_waffle.R rename to R/hc-charts.R index 7e5a8a96..13a88a50 100644 --- a/R/hchart_waffle.R +++ b/R/hc-charts.R @@ -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 @@ -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) %>% @@ -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() @@ -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 %>% @@ -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 - } diff --git a/man/hcbar.Rd b/man/hcbar.Rd new file mode 100644 index 00000000..6a044e5d --- /dev/null +++ b/man/hcbar.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hc-charts.R +\name{hcbar} +\alias{hcbar} +\title{Function to make a bar chart} +\usage{ +hcbar(x, ...) +} +\arguments{ +\item{x}{A character o factor vector.} + +\item{...}{Aditional shared arguments for the data series (http://api.highcharts.com/highcharts#series).} +} +\description{ +Function to make a bar chart +} + diff --git a/man/hcboxplot.Rd b/man/hcboxplot.Rd new file mode 100644 index 00000000..e1a3e5a1 --- /dev/null +++ b/man/hcboxplot.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hc-charts.R +\name{hcboxplot} +\alias{hcboxplot} +\title{Function to make a boxplot} +\usage{ +hcboxplot(x, by = NULL, outliers = TRUE, ...) +} +\arguments{ +\item{x}{A numeric vector.} + +\item{by}{A character vector same length of \code{x}} + +\item{outliers}{A boolean value to show or not the outliers} + +\item{...}{Aditional shared arguments for the data series (http://api.highcharts.com/highcharts#series).} +} +\description{ +Function to make a boxplot +} + diff --git a/man/hchart_waffle.Rd b/man/hchart_waffle.Rd deleted file mode 100644 index 9a08d48d..00000000 --- a/man/hchart_waffle.Rd +++ /dev/null @@ -1,34 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/hchart_waffle.R -\name{hchart_waffle} -\alias{hchart_waffle} -\title{Function to create waffle charts} -\usage{ -hchart_waffle(labels, counts, rows = NULL, icons = NULL, size = 4) -} -\arguments{ -\item{labels}{A character vector} - -\item{counts}{A integer vector} - -\item{rows}{A integer to set} - -\item{icons}{A character vector same length (o length 1) as labels} - -\item{size}{Font size} -} -\description{ -Function to create waffle charts -} -\examples{ - -hchart_waffle(c("nice", "good"), c(10, 20)) - -hchart_waffle(c("nice", "good"), c(10, 20), size = 10) - -hchart_waffle(c("nice", "good"), c(100, 200), icons = "child") - -hchart_waffle(c("car", "truck", "plane"), c(50, 20, 10), icons = c("car", "truck", "plane")) - -} - diff --git a/man/hchist.Rd b/man/hchist.Rd new file mode 100644 index 00000000..ec60b665 --- /dev/null +++ b/man/hchist.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hc-charts.R +\name{hchist} +\alias{hchist} +\title{Function to make an histogram} +\usage{ +hchist(x, ...) +} +\arguments{ +\item{x}{A numeric vector.} + +\item{...}{Aditional shared arguments for the data series (http://api.highcharts.com/highcharts#series).} +} +\description{ +Function to make an histogram +} + diff --git a/man/hcpie.Rd b/man/hcpie.Rd new file mode 100644 index 00000000..9682ba7e --- /dev/null +++ b/man/hcpie.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hc-charts.R +\name{hcpie} +\alias{hcpie} +\title{Function to make a pie chart} +\usage{ +hcpie(x, ...) +} +\arguments{ +\item{x}{A character o factor vector.} + +\item{...}{Aditional shared arguments for the data series (http://api.highcharts.com/highcharts#series).} +} +\description{ +Function to make a pie chart +} + diff --git a/man/hcwaffle.Rd b/man/hcwaffle.Rd new file mode 100644 index 00000000..78582f59 --- /dev/null +++ b/man/hcwaffle.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hc-charts.R +\name{hcwaffle} +\alias{hcwaffle} +\title{Function to create waffle charts} +\usage{ +hcwaffle(labels, counts, rows = NULL, icons = NULL, size = 4) +} +\arguments{ +\item{labels}{A character vector} + +\item{counts}{A integer vector} + +\item{rows}{A integer to set} + +\item{icons}{A character vector same length (o length 1) as labels} + +\item{size}{Font size} +} +\description{ +Function to create waffle charts +} +\examples{ + +hcwaffle(c("nice", "good"), c(10, 20)) + +hcwaffle(c("nice", "good"), c(10, 20), size = 10) + +hcwaffle(c("nice", "good"), c(100, 200), icons = "child") + +hcwaffle(c("car", "truck", "plane"), c(50, 20, 10), icons = c("car", "truck", "plane")) + +} +