Shorcut for tidy data frame a la ggplot2/qplot

Description

Function to create chart from tidy data frames. As same as qplot you can use aesthetic including the group variable

Usage

1

Arguments

hc

A highchart htmlwidget object.

data

A data.frame object.

type

The type of chart. Possible values are line, scatter, point, colum, columnrange, etc. See http://api.highcharts.com/highcharts#series.

...

Aesthetic mappings, x y group color low high.

Details

The types supported are line, column, point, polygon, columrange, spline, areaspline among others.

Automatically parsed de data frame (to a list o series). You you can use the default parameters of highcharts such as x, y, z, color, name, low, high for each series, for example check http://api.highcharts.com/highcharts#series<bubble>.data.

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require("dplyr")
n <- 100
df <- data_frame(
  x = rnorm(n),
  y = x * 2 + rnorm(n),
  w =  x^2
  )
  
hc_add_series_df(highchart(), data = df, type = "point", x = x, y = y)
hc_add_series_df(highchart(), data = df, type = "point", color = w)
hc_add_series_df(highchart(), data = df, type = "point", color = w, size = y)

m <- 100
s <- cumsum(rnorm(m))
e <- 2 + rbeta(m, 2, 2)

df2 <- data_frame(
  var = seq(m),
  l = s - e,
  h = s + e,
  n = paste("I'm point ", var)
)

hc_add_series_df(highchart(), data = df2, type = "columnrange",
                 x = var, low = l, high = h, name = n, color = var)

hc_add_series_df(highchart(), iris, "point",
                      x = Sepal.Length, y = Sepal.Width, group = Species)

  
data(mpg, package = "ggplot2")

# point and scatter is the same
hc_add_series_df(highchart(), mpg, "scatter", x = displ, y = cty)
hc_add_series_df(highchart(), mpg, "point", x = displ, y = cty,
                      group = manufacturer)
     

mpgman <- count(mpg, manufacturer)
hc_add_series_df(highchart(), mpgman, "column", x = manufacturer, y = n) %>% 
  hc_xAxis(type = "category")

mpgman2 <- count(mpg, manufacturer, year)
hc_add_series_df(highchart(), mpgman2, "bar", x = manufacturer, y = n, group = year) %>% 
  hc_xAxis(type = "category")
  
data(economics, package = "ggplot2")

hc_add_series_df(highchart(), economics, "line", x = date, y = unemploy) %>% 
  hc_xAxis(type = "datetime")

data(economics_long, package = "ggplot2")

economics_long2 <- filter(economics_long,
                          variable %in% c("pop", "uempmed", "unemploy"))
                          
hc_add_series_df(highchart(), economics_long2, "line", x = date,
                 y = value01, group = variable) %>% 
  hc_xAxis(type = "datetime")

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.