Skip to content

Commit b4164a7

Browse files
committed
doc ready!
1 parent 8849f56 commit b4164a7

33 files changed

+440
-180
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Description: A wrapper for the 'Highcharts' library including
66
shortcut functions to plot R objects. 'Highcharts'
77
<http://www.highcharts.com/> is a charting library offering
88
numerous chart types with a simple configuration syntax.
9-
Date: 2015-12-11
9+
Date: 2016-01-12
1010
Author: Joshua Kunst <[email protected]>
1111
Maintainer: Joshua Kunst <[email protected]>
1212
License: MIT + file LICENSE

R/api.R

+59-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#' @import rlist assertthat
1+
#' @import rlist
22
.hc_opt <- function(hc, name, ...) {
33

4-
assert_that(.is_highchart(hc))
4+
assertthat::assert_that(.is_highchart(hc))
55

66
if (is.null(hc$x$hc_opts[[name]])) {
77

@@ -204,9 +204,10 @@ hc_tooltip <- function(hc, ...) {
204204
#' The plotOptions is a wrapper object for config objects for each series type. The config
205205
#' objects for each series can also be overridden for each series item as given in the series array.
206206
#'
207-
#' Configuration options for the series are given in three levels. Options for all series in a chart are given in the
208-
#' plotOptions object. Then options for all series of a specific type are given in the plotOptions of that type, for example
209-
#' \code{hc_plotOptions(line = list(...))}. Next, options for one single series are given in the series array.
207+
#' Configuration options for the series are given in three levels. Options for all series in a
208+
#' chart are given with the \code{hc_plotOptions} function. Then options for all series of a specific
209+
#' type are given in the plotOptions of that type, for example \code{hc_plotOptions(line = list(...))}.
210+
#' Next, options for one single series are given in the series array.
210211
#'
211212
#' @param hc A \code{highchart} \code{htmlwidget} object.
212213
#' @param ... Arguments are defined in \url{http://api.highcharts.com/highcharts#plotOptions}.
@@ -232,7 +233,7 @@ hc_tooltip <- function(hc, ...) {
232233
#'
233234
#' hc
234235
#'
235-
#' #' override the `blue` option with the explicit parameter
236+
#' # override the `blue` option with the explicit parameter
236237
#' hc %>%
237238
#' hc_add_serie(name = "London",
238239
#' data = citytemp$new_york,
@@ -247,12 +248,24 @@ hc_plotOptions <- function(hc, ...) {
247248

248249
#' Adding credits options to highchart objects
249250
#'
250-
#' \code{highcarter} by default don't put credits label. You can add credits
251-
#' using these options.
251+
#' \code{highcarter} by default don't put credits in the chart.
252+
#' You can add credits using these options.
252253
#'
253254
#' @param hc A \code{highchart} \code{htmlwidget} object.
254255
#' @param ... Arguments defined in \url{http://api.highcharts.com/highcharts#credits}.
255-
#'
256+
#'
257+
#' @examples
258+
#'
259+
#' require("dplyr")
260+
#'
261+
#' data("citytemp")
262+
#'
263+
#' highchart() %>%
264+
#' hc_xAxis(categories = citytemp$month) %>%
265+
#' hc_add_serie(name = "Tokyo", data = citytemp$tokyo, type = "bar") %>%
266+
#' hc_credits(enabled = TRUE, text = "htmlwidgets.org",
267+
#' href = "http://www.htmlwidgets.org/")
268+
#'
256269
#' @export
257270
hc_credits <- function(hc, ...) {
258271

@@ -266,7 +279,41 @@ hc_credits <- function(hc, ...) {
266279
#'
267280
#' @param hc A \code{highchart} \code{htmlwidget} object.
268281
#' @param ... Arguments are defined in \url{http://www.highcharts.com/docs/maps/color-axis}.
269-
#'
282+
#'
283+
#' @examples
284+
#'
285+
#' require("dplyr")
286+
#'
287+
#' nyears <- 5
288+
#'
289+
#' df <- expand.grid(seq(12) - 1, seq(nyears) - 1)
290+
#' df$value <- abs(seq(nrow(df)) + 10 * rnorm(nrow(df))) + 10
291+
#' df$value <- round(df$value, 2)
292+
#' ds <- setNames(list.parse2(df), NULL)
293+
#'
294+
#'
295+
#' hc <- highchart() %>%
296+
#' hc_chart(type = "heatmap") %>%
297+
#' hc_title(text = "Simulated values by years and months") %>%
298+
#' hc_xAxis(categories = month.abb) %>%
299+
#' hc_yAxis(categories = 2016 - nyears + seq(nyears)) %>%
300+
#' hc_add_serie(name = "value", data = ds)
301+
#'
302+
#' hc_colorAxis(hc, minColor = "#FFFFFF", maxColor = "#434348")
303+
#'
304+
#' hc_colorAxis(hc, minColor = "#FFFFFF", maxColor = "#434348",
305+
#' type = "logarithmic")
306+
#'
307+
#'
308+
#' require("viridisLite")
309+
#'
310+
#' n <- 4
311+
#' stops <- data_frame(q = 0:n/n,
312+
#' c = substring(viridis(n + 1), 0, 7))
313+
#' stops <- list.parse2(stops)
314+
#'
315+
#' hc_colorAxis(hc, stops = stops, max = 75)
316+
#'
270317
#' @export
271318
hc_colorAxis <- function(hc, ...) {
272319

@@ -292,14 +339,8 @@ hc_colorAxis <- function(hc, ...) {
292339
#' hc_xAxis(categories = citytemp$month) %>%
293340
#' hc_add_serie(name = "Tokyo", data = citytemp$tokyo) %>%
294341
#' hc_add_serie(name = "London", data = citytemp$london) %>%
295-
#' hc_exporting(enabled = FALSE)
296-
#'
297-
#'
298-
#' highchart() %>%
299-
#' hc_xAxis(categories = citytemp$month) %>%
300-
#' hc_add_serie(name = "Tokyo", data = citytemp$tokyo) %>%
301-
#' hc_add_serie(name = "London", data = citytemp$london) %>%
302-
#' hc_exporting(filename = "custom-file-name")
342+
#' hc_exporting(enabled = TRUE,
343+
#' filename = "custom-file-name")
303344
#'
304345
#' @export
305346
hc_exporting <- function(hc, ...) {
@@ -341,11 +382,9 @@ hc_add_serie <- function(hc, ...) {
341382

342383
#' Removing series to highchart objects
343384
#'
344-
#' @param hc A \code{highchart} \code{htmlwidget} object.
345385
#' @param name The serie's name to delete.
346386
#'
347387
#' @rdname hc_add_serie
348-
#'
349388
#' @export
350389
hc_rm_serie <- function(hc, name = NULL) {
351390

R/assertthat.R

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#' @import assertthat
12
.is_highchart <- function(hc){
2-
are_equal(class(hc), c("highchart", "htmlwidget"))
3+
assertthat::are_equal(class(hc), c("highchart", "htmlwidget"))
34
}
45

56
assertthat::on_failure(.is_highchart) <- function(call, env) {
@@ -9,11 +10,11 @@ assertthat::on_failure(.is_highchart) <- function(call, env) {
910
}
1011

1112
.is_hc_theme <- function(hc_theme){
12-
are_equal(class(hc_theme), "hc_theme")
13+
assertthat::are_equal(class(hc_theme), "hc_theme")
1314
}
1415

1516
assertthat::on_failure(.is_highchart) <- function(call, env) {
1617

17-
"The theme used is not a hc_theme object"
18+
"The theme used is not from hc_theme class"
1819

1920
}

R/data-citytemp.R

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#' @name citytemp
1919
#' @usage citytemp
2020
#' @format A \code{data frame} with 12 observations and 5 variables.
21-
#' @rdname data
2221
#' @examples
2322
#' data(citytemp)
2423
#' citytemp

R/data-favorite_bars.R

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#' @name favorite_bars
1616
#' @usage favorite_bars
1717
#' @format A \code{data frame} with 5 observations and 2 variables.
18-
#' @rdname data
1918
#' @examples
2019
#' data(favorite_bars)
2120
#' favorite_bars

R/data-favorite_pies.R

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#' @name favorite_pies
1616
#' @usage favorite_pies
1717
#' @format A \code{data frame} with 5 observations and 2 variables.
18-
#' @rdname data
1918
#' @examples
2019
#' data(favorite_pies)
2120
#' favorite_pies

R/helpers.R

+27-11
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
#'
33
#' This function is similiar to \code{rlist::list.parse} but this removes names.
44
#'
5-
#' @param df A data frame to
5+
#' @param df A data frame to parse to list
66
#'
7-
#' @importFrom stats setNames
7+
#' @examples
8+
#'
9+
#' x <- data.frame(a=1:3,type=c('A','C','B'))
10+
#'
11+
#' list.parse2(x)
812
#'
9-
#' @rdname helpers
13+
#' @importFrom stats setNames
1014
#' @export
1115
list.parse2 <- function(df) {
1216

17+
assertthat::assert_that(is.data.frame(df))
18+
1319
setNames(apply(df, 1, function(r) as.list(as.vector(r))), NULL)
1420

1521
}
@@ -20,26 +26,33 @@ list.parse2 <- function(df) {
2026
#'
2127
#' @param x A vector string.
2228
#'
29+
#' @examples
30+
#'
31+
#' str_to_id(" A string _ with Underscores ")
32+
#'
2333
#' @importFrom stringr str_to_lower str_replace_all
24-
#' @rdname helpers
2534
#' @export
2635
str_to_id <- function(x) {
2736

28-
assert_that(is.character(x))
37+
assertthat::assert_that(is.character(x))
2938

3039
x %>%
3140
str_trim() %>%
3241
str_to_lower() %>%
3342
str_replace_all("\\s+", "_") %>%
34-
iconv("latin1", "ASCII", sub="")
43+
str_replace_all("_+", "_") %>%
44+
iconv("latin1", "ASCII", sub = "")
3545

3646
}
3747

3848
#' Get default colors for Highcharts theme
3949
#'
4050
#' Get color used in highcharts charts.
4151
#'
42-
#' @rdname helpers
52+
#' @examples
53+
#'
54+
#' hc_get_colors()[1:5]
55+
#'
4356
#' @export
4457
hc_get_colors <- function() {
4558

@@ -50,13 +63,16 @@ hc_get_colors <- function() {
5063

5164
#' Get dash styles
5265
#'
53-
#' Get dash style to use on hichartrs objects.
66+
#' Get dash style to use on highcharts objects.
67+
#'
68+
#' @examples
69+
#'
70+
#' hc_get_dash_styles()[1:5]
5471
#'
55-
#' @rdname helpers
5672
#' @export
5773
hc_get_dash_styles <- function() {
5874

59-
c("Solid", "ShortDash", "ShortDot", "ShortDashDot", "ShortDashDotDot", "Dot",
60-
"Dash", "LongDash", "DashDot", "LongDashDot", "LongDashDotDot")
75+
c("Solid", "ShortDash", "ShortDot", "ShortDashDot", "ShortDashDotDot",
76+
"Dot", "Dash", "LongDash", "DashDot", "LongDashDot", "LongDashDotDot")
6177

6278
}

R/highcharter-package.R

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#' An \code{htmlwidget} interface to the
2-
#' \href{http://www.highcharts.com/}{Highcharts} javascript chart library
2+
#' Highcharts javascript chart library
3+
#'
4+
#' Highcarts \url{http://www.highcharts.com/} is a mature javascript
5+
#' charting library. Highcharts provide a various type of charts, from
6+
#' scatters to heatmaps or treemaps.
7+
#'
38
#' @name hicharter
49
#' @docType package
510
#' @author Joshua Kunst (@@jbkunst)

R/shortcuts.R

+11-11
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#' @export
3030
hc_add_serie_ts2 <- function(hc, ts, ...) {
3131

32-
assert_that(is.ts(ts), .is_highchart(hc))
32+
assertthat::assert_that(is.ts(ts), .is_highchart(hc))
3333

3434
# http://stackoverflow.com/questions/29202021/r-how-to-extract-dates-from-a-time-series
3535
dates <- time(ts) %>%
@@ -59,8 +59,8 @@ hc_add_serie_ts2 <- function(hc, ts, ...) {
5959
#' require("ggplot2")
6060
#' data(economics, package = "ggplot2")
6161
#'
62-
#' hc_add_serie_ts(highchart(),
63-
#' economics$psavert, economics$date,
62+
#' hc_add_serie_ts(hc = highchart(),
63+
#' values = economics$psavert, dates = economics$date,
6464
#' name = "Personal Savings Rate")
6565
#' }
6666
#'
@@ -69,7 +69,7 @@ hc_add_serie_ts2 <- function(hc, ts, ...) {
6969
#' @export
7070
hc_add_serie_ts <- function(hc, values, dates, ...) {
7171

72-
assert_that(.is_highchart(hc), is.numeric(values), is.date(dates))
72+
assertthat::assert_that(.is_highchart(hc), is.numeric(values), is.date(dates))
7373

7474
timestamps <- dates %>%
7575
zoo::as.Date() %>%
@@ -148,8 +148,8 @@ hc_add_serie_ts <- function(hc, values, dates, ...) {
148148
hc_add_serie_scatter <- function(hc, x, y, z = NULL, color = NULL, label = NULL,
149149
showInLegend = FALSE, viridis.option = "D", ...) {
150150

151-
assert_that(.is_highchart(hc), length(x) == length(y),
152-
is.numeric(x), is.numeric(y))
151+
assertthat::assert_that(.is_highchart(hc), length(x) == length(y),
152+
is.numeric(x), is.numeric(y))
153153

154154
df <- data_frame(x, y)
155155

@@ -228,9 +228,9 @@ hc_add_serie_scatter <- function(hc, x, y, z = NULL, color = NULL, label = NULL,
228228
#' @export
229229
hc_add_serie_labels_values <- function(hc, labels, values, colors = NULL, ...) {
230230

231-
assert_that(.is_highchart(hc),
232-
is.numeric(values),
233-
length(labels) == length(values))
231+
assertthat::assert_that(.is_highchart(hc),
232+
is.numeric(values),
233+
length(labels) == length(values))
234234

235235
df <- data_frame(name = labels, y = values)
236236

@@ -292,8 +292,8 @@ hc_add_serie_labels_values <- function(hc, labels, values, colors = NULL, ...) {
292292
#' @export
293293
hc_add_serie_treemap <- function(hc, tm, ...) {
294294

295-
assert_that(.is_highchart(hc),
296-
is.list(tm))
295+
assertthat::assert_that(.is_highchart(hc),
296+
is.list(tm))
297297

298298
df <- tm$tm %>%
299299
tbl_df() %>%

R/theme.R

+30
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#'
33
#' Function to create highcharts themes.
44
#'
5+
#' More examples are in http://www.highcharts.com/docs/chart-design-and-style/themes.
6+
#'
57
#' @param ... A named list with the parameters.
68
#'
79
#' @examples
@@ -64,6 +66,16 @@ hc_theme <- function(...){
6466
#' @param hc A highchart object
6567
#' @param hc_thm A highchart theme object (\code{"hc_theme"} class)
6668
#'
69+
#' @examples
70+
#'
71+
#' require("dplyr")
72+
#'
73+
#' highchart() %>%
74+
#' hc_add_serie(data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2,
75+
#' 26.5, 23.3, 18.3, 13.9, 9.6),
76+
#' type = "column") %>%
77+
#' hc_add_theme(hc_theme_sandsignika())
78+
#'
6779
#' @export
6880
hc_add_theme <- function(hc, hc_thm){
6981

@@ -84,6 +96,24 @@ hc_add_theme <- function(hc, hc_thm){
8496
#'
8597
#' @param ... A \code{hc_theme} objects.
8698
#'
99+
#' @examples
100+
#'
101+
#' thm <- hc_theme_merge(
102+
#' hc_theme_darkunica(),
103+
#' hc_theme(
104+
#' chart = list(
105+
#' backgroundColor = "transparent",
106+
#' divBackgroundImage = "http://cdn.wall-pix.net/albums/art-3Dview/00025095.jpg"
107+
#' ),
108+
#' title = list(
109+
#' style = list(
110+
#' color = 'white',
111+
#' fontFamily = "Erica One"
112+
#' )
113+
#' )
114+
#' )
115+
#' )
116+
#'
87117
#' @export
88118
hc_theme_merge <- function(...){
89119

0 commit comments

Comments
 (0)