diff --git a/R/api.R b/R/api.R index f1782758..531210c5 100644 --- a/R/api.R +++ b/R/api.R @@ -186,6 +186,7 @@ hc_legend <- function(hc, ...) { #' hc_add_serie(name = "Tokyo", data = citytemp$tokyo) %>% #' hc_add_serie(name = "London", data = citytemp$london) %>% #' hc_tooltip(crosshairs = TRUE, backgroundColor = "gray", +#' headerFormat = "This is a custom header
", #' shared = TRUE, borderWidth = 5) #' #' @param hc A \code{highchart} \code{htmlwidget} object. @@ -208,7 +209,34 @@ hc_tooltip <- function(hc, ...) { #' \code{hc_plotOptions(line = list(...))}. Next, options for one single series are given in the series array. #' #' @param hc A \code{highchart} \code{htmlwidget} object. -#' @param ... Arguments are defined in \url{http://api.highcharts.com/highcharts#plotOptions}. +#' @param ... Arguments are defined in \url{http://api.highcharts.com/highcharts#plotOptions}. +#' +#' @examples +#' +#' require("dplyr") +#' +#' data(citytemp) +#' +#' hc <- highchart() %>% +#' hc_plotOptions(line = list(color = "blue", +#' marker = list( +#' fillColor = "white", +#' lineWidth = 2, +#' lineColor = NULL +#' ) +#' )) %>% +#' hc_add_serie(name = "Tokyo", data = citytemp$tokyo) %>% +#' hc_add_serie(name = "London", data = citytemp$london, +#' marker = list(fillColor = "black")) +#' +#' +#' hc +#' +#' #' override the `blue` option with the explicit parameter +#' hc %>% +#' hc_add_serie(name = "London", +#' data = citytemp$new_york, +#' color = "red") #' #' @export hc_plotOptions <- function(hc, ...) { @@ -219,7 +247,7 @@ hc_plotOptions <- function(hc, ...) { #' Adding Color Axis options to highchart objects #' -#' +#' Function to set the axis color to highcharts objects. #' #' @param hc A \code{highchart} \code{htmlwidget} object. #' @param ... Arguments are defined in \url{http://www.highcharts.com/docs/maps/color-axis}. diff --git a/R/shortcuts.R b/R/shortcuts.R index f734ab67..3506ef21 100644 --- a/R/shortcuts.R +++ b/R/shortcuts.R @@ -298,11 +298,13 @@ hc_add_serie_treemap <- function(hc, tm, ...) { tbl_df() %>% select_("-x0", "-y0", "-w", "-h", "-stdErr", "-vColorValue") %>% rename_("value" = "vSize", "valuecolor" = "vColor") %>% - map_if(is.factor, as.character) + purrr::map_if(is.factor, as.character) %>% + data.frame(stringsAsFactors = FALSE) %>% + tbl_df() ndepth <- which(names(df) == "value") - 1 - ds <- ldply(seq(ndepth), function(lvl){ # lvl <- sample(size = 1, seq(ndepth)) + ds <- ldply(seq(ndepth), function(lvl){ # lvl <- sample(seq(ndepth), size = 1) df2 <- df %>% filter_(sprintf("level == %s", lvl)) %>% diff --git a/R/theme.R b/R/theme.R index 4c915203..db0fcf78 100644 --- a/R/theme.R +++ b/R/theme.R @@ -1,35 +1,15 @@ -#' Add themes to a highchart object -#' -#' Add highcharts themes to a highchart object. -#' -#' @param hc A highchart object -#' @param hc_thm A highchart theme object (\code{"hc_theme"} class) -#' @export -hc_add_theme <- function(hc, hc_thm){ - - assert_that(.is_highchart(hc), - .is_hc_theme(hc_thm)) - - hc$x$fonts <- unique(c(hc$x$fonts, .hc_get_fonts(hc_thm))) - - hc$x$theme <- hc_thm - - hc - -} - #' Highchart theme constructor #' #' Function to create highcharts themes. #' -#' @param ... Usually named list +#' @param ... A named list with the parameters. #' #' @examples #' -#' \dontrun{ +#' require("dplyr") #' #' hc <- highchart(debug = TRUE) %>% -#' hc_add_serie_scatter(mtcars$wt, mtcars$mpg, mtcars$cyl) %>% +#' hc_add_serie_scatter(mtcars$wt, mtcars$mpg, color = mtcars$cyl) %>% #' hc_chart(zoomType = "xy") %>% #' hc_title(text = "Motor Trend Car Road Tests") %>% #' hc_subtitle(text = "Motor Trend Car Road Tests") %>% @@ -70,8 +50,6 @@ hc_add_theme <- function(hc, hc_thm){ #' #' hc %>% hc_add_theme(thm) #' -#' } -#' #' @export hc_theme <- function(...){ @@ -79,19 +57,24 @@ hc_theme <- function(...){ } -#' @importFrom stringr str_replace_all str_replace str_trim -.hc_get_fonts <- function(lst){ +#' Add themes to a highchart object +#' +#' Add highcharts themes to a highchart object. +#' +#' @param hc A highchart object +#' @param hc_thm A highchart theme object (\code{"hc_theme"} class) +#' +#' @export +hc_add_theme <- function(hc, hc_thm){ - unls <- unlist(lst) - unls <- unls[grepl("fontFamily", names(unls))] + assert_that(.is_highchart(hc), + .is_hc_theme(hc_thm)) - fonts <- unls %>% - str_replace_all(",\\s+sans-serif|,\\s+serif", "") %>% - str_replace("\\s+", "+") %>% - str_trim() %>% - unlist() + hc$x$fonts <- unique(c(hc$x$fonts, .hc_get_fonts(hc_thm))) - fonts + hc$x$theme <- hc_thm + + hc } @@ -99,7 +82,7 @@ hc_theme <- function(...){ #' #' Function to combine hc_theme objects. #' -#' @param ... \code{hc_theme} objects +#' @param ... A \code{hc_theme} objects. #' #' @export hc_theme_merge <- function(...){ @@ -113,3 +96,19 @@ hc_theme_merge <- function(...){ theme } + +#' @importFrom stringr str_replace_all str_replace str_trim +.hc_get_fonts <- function(lst){ + + unls <- unlist(lst) + unls <- unls[grepl("fontFamily", names(unls))] + + fonts <- unls %>% + str_replace_all(",\\s+sans-serif|,\\s+serif", "") %>% + str_replace("\\s+", "+") %>% + str_trim() %>% + unlist() + + fonts + +} diff --git a/R/zzz.R b/R/zzz.R index 3d5f6b28..e46a74d3 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -18,13 +18,15 @@ drillUpText = "Back to list(series.name)", invalidDate = NULL, loading = "Loading...", - months = c( "January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December"), + months = c( "January" , "February" , "March" , "April" , "May" , "June" , + "July" , "August" , "September" , "October" , "November" , "December"), noData = "No data to display", numericSymbols = c( "k" , "M" , "G" , "T" , "P" , "E"), printChart = "Print chart", resetZoom = "Reset zoom", resetZoomTitle = "Reset zoom level 1:1", - shortMonths = c( "Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec"), + shortMonths = c( "Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , + "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec"), thousandsSep = " ", weekdays = c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") ), diff --git a/man/hc_colorAxis.Rd b/man/hc_colorAxis.Rd index cc33ed9e..e3eff884 100644 --- a/man/hc_colorAxis.Rd +++ b/man/hc_colorAxis.Rd @@ -12,6 +12,6 @@ hc_colorAxis(hc, ...) \item{...}{Arguments are defined in \url{http://www.highcharts.com/docs/maps/color-axis}.} } \description{ -Adding Color Axis options to highchart objects +Function to set the axis color to highcharts objects. } diff --git a/man/hc_plotOptions.Rd b/man/hc_plotOptions.Rd index 3bc7307d..5caa248f 100644 --- a/man/hc_plotOptions.Rd +++ b/man/hc_plotOptions.Rd @@ -20,4 +20,32 @@ Configuration options for the series are given in three levels. Options for all plotOptions object. Then options for all series of a specific type are given in the plotOptions of that type, for example \code{hc_plotOptions(line = list(...))}. Next, options for one single series are given in the series array. } +\examples{ + +require("dplyr") + +data(citytemp) + +hc <- highchart() \%>\% + hc_plotOptions(line = list(color = "blue", + marker = list( + fillColor = "white", + lineWidth = 2, + lineColor = NULL + ) + )) \%>\% + hc_add_serie(name = "Tokyo", data = citytemp$tokyo) \%>\% + hc_add_serie(name = "London", data = citytemp$london, + marker = list(fillColor = "black")) + + +hc + +#' override the `blue` option with the explicit parameter +hc \%>\% + hc_add_serie(name = "London", + data = citytemp$new_york, + color = "red") + +} diff --git a/man/hc_theme.Rd b/man/hc_theme.Rd index a597ad79..2f37392a 100644 --- a/man/hc_theme.Rd +++ b/man/hc_theme.Rd @@ -7,17 +7,17 @@ hc_theme(...) } \arguments{ -\item{...}{Usually named list} +\item{...}{A named list with the parameters.} } \description{ Function to create highcharts themes. } \examples{ -\dontrun{ +require("dplyr") hc <- highchart(debug = TRUE) \%>\% - hc_add_serie_scatter(mtcars$wt, mtcars$mpg, mtcars$cyl) \%>\% + hc_add_serie_scatter(mtcars$wt, mtcars$mpg, color = mtcars$cyl) \%>\% hc_chart(zoomType = "xy") \%>\% hc_title(text = "Motor Trend Car Road Tests") \%>\% hc_subtitle(text = "Motor Trend Car Road Tests") \%>\% @@ -60,5 +60,3 @@ hc \%>\% hc_add_theme(thm) } -} - diff --git a/man/hc_theme_merge.Rd b/man/hc_theme_merge.Rd index faf03fc6..5faf443a 100644 --- a/man/hc_theme_merge.Rd +++ b/man/hc_theme_merge.Rd @@ -7,7 +7,7 @@ hc_theme_merge(...) } \arguments{ -\item{...}{\code{hc_theme} objects} +\item{...}{A \code{hc_theme} objects.} } \description{ Function to combine hc_theme objects. diff --git a/man/hc_tooltip.Rd b/man/hc_tooltip.Rd index d47fcdc3..09479dff 100644 --- a/man/hc_tooltip.Rd +++ b/man/hc_tooltip.Rd @@ -25,6 +25,7 @@ highchart() \%>\% hc_add_serie(name = "Tokyo", data = citytemp$tokyo) \%>\% hc_add_serie(name = "London", data = citytemp$london) \%>\% hc_tooltip(crosshairs = TRUE, backgroundColor = "gray", + headerFormat = "This is a custom header
", shared = TRUE, borderWidth = 5) } diff --git a/no_build/index.R b/no_build/index.R index 5efd6bc6..97a3d432 100644 --- a/no_build/index.R +++ b/no_build/index.R @@ -293,31 +293,17 @@ hc ##' # Shorcuts for add Data (data series) #### -##' ## Time Series #### - -data(economics, package = "ggplot2") - -highchart() %>% - hc_add_serie_ts(economics$psavert, economics$date, - name = "Personal Savings Rate") - -#' There's a `hc_add_serie_ts2` which recieve a `ts`object. - -highchart() %>% - hc_add_serie_ts2(AirPassengers, color = "#26838E") - -highchart() %>% - hc_title(text = "Monthly Deaths from Lung Diseases in the UK") %>% - hc_subtitle(text = "Deaths from bronchitis, emphysema and asthma") %>% - hc_add_serie_ts2(fdeaths, name = "Female") %>% - hc_add_serie_ts2(mdeaths, name = "Male") - -##' ## Scatter plot #### +##' ## Scatter #### highchart() %>% hc_title(text = "Simple scatter chart") %>% hc_add_serie_scatter(mtcars$wt, mtcars$mpg) +highchart() %>% + hc_title(text = "Scatter chart with color") %>% + hc_add_serie_scatter(mtcars$wt, mtcars$mpg, + color = mtcars$hp) + highchart() %>% hc_title(text = "Scatter chart with size") %>% hc_add_serie_scatter(mtcars$wt, mtcars$mpg, @@ -328,11 +314,6 @@ highchart() %>% hc_add_serie_scatter(mtcars$wt, mtcars$mpg, mtcars$drat, mtcars$hp) -highchart() %>% - hc_title(text = "Scatter chart with color and no size") %>% - hc_add_serie_scatter(mtcars$wt, mtcars$mpg, - color = mtcars$hp) - highchart(height = 500) %>% hc_title(text = "A complete example for Scatter") %>% hc_add_serie_scatter(mtcars$wt, mtcars$mpg, @@ -352,7 +333,7 @@ highchart(height = 500) %>% "HP{point.valuecolor} hp"), footerFormat = "") -# or We can add series one by one. +#' Or we can add series one by one. hc <- highchart() for (cyl in unique(mtcars$cyl)) { hc <- hc %>% @@ -364,6 +345,25 @@ for (cyl in unique(mtcars$cyl)) { hc +##' ## Time Series #### + +data(economics, package = "ggplot2") + +highchart() %>% + hc_add_serie_ts(economics$psavert, economics$date, + name = "Personal Savings Rate") + +#' There's a `hc_add_serie_ts2` which recieve a `ts`object. + +highchart() %>% + hc_add_serie_ts2(AirPassengers, color = "#26838E") + +highchart() %>% + hc_title(text = "Monthly Deaths from Lung Diseases in the UK") %>% + hc_subtitle(text = "Deaths from bronchitis, emphysema and asthma") %>% + hc_add_serie_ts2(fdeaths, name = "Female") %>% + hc_add_serie_ts2(mdeaths, name = "Male") + ##' ## Treemaps #### #' #' Here we use the `treemap` package to create a treemap object and then