swi_rcharts: Helper functions for rCharts

Description Usage Arguments Examples

Description

Misc helper functions to create interactive charts with rCharts

Create a responsive html page along with javascript library files

Usage

1
2
3
4
5
6
7
8
hSeries(x, y, z, name, color = NULL, series)

hSeries2(df, series)

hChart2responsiveHTML(hChart.html, output.html = "rHighchart.html",
  output = ".", source = "source:",
  author = "Duc-Quang Nguyen | swissinfo.ch", h2 = "title",
  descr = "descriptive text", h3 = "subtitle")

Arguments

x, y, z

a numeric of same length

color, name, series

a character of same length

series

a character, the column name in df to split the data in different highcharts' series

df

a data.frame

hChart.html, output.html

character file path to the input highchart html and the output reponsive html

output

a path to a folder where the reponsive html file and depending js libraries will be saved

source, author, h2, descr, h3

characters

overwrite

a logical, should the output file be overwritten?

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
## Not run: 
#Example for hSeries to create a labelled bubble scatterchart with rCharts/highcharts

library(swiTheme)
a <- rCharts::Highcharts$new()
x <- 1:10
y <- seq(1, 100, 10)
z <- 10:1
color <- rep(c("grey", "red"), 5)
name <- c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")
series <- c(rep(c("blob", "poop", "doop"), 3), "asdf")
a$series(hSeries(x,y,z,name, color, series))

# tweak the bubble plot
a$chart(zoomType = "xy", type = "bubble")
a$plotOptions(bubble = list(dataLabels = list(enabled = T, style = list(textShadow = 'none') ,
color = '#aa8959', formatter = "#! function() { return this.point.name; } !#")))

a$colors(swi_rpal)
a$tooltip(formatter = "#! function() { return this.point.name + ':' +this.x + ', ' + this.y; } !#")
a$xAxis(title = list(text = "important indicator", align = "high"), lineColor = list ('#FF0000'))
a

hChart.html <- tempfile("hchart_labelledBubble.html")
a$save(hChart.html)

## End(Not run)
hSeries2 <- hSeries2(data.frame(x = x, y = y, z = z, color = color, name = name, series = series), "series")
 b <- rCharts::Highcharts$new()  
b$series(hSeries2)

## Not run: 
# Example of converting a highcharts-rCharts html chart into a responsive one

hChart2responsiveHTML(hChart.html, source = "source: stupid data")
browseURL(hChart.html)

## End(Not run)

d-qn/swiRcharts documentation built on May 14, 2019, 3:04 p.m.