The c3
package is a
wrapper, or htmlwidget, for
the C3 javascript charting library by Masayuki Tanaka. You will
find this package useful if you are wanting to create a chart using R and embedding it in a Rmarkdown
document or Shiny App.
The C3
library is very versatile and includes a lot of
options. Currently this package wraps most of the C3
options object. Even with this
current limitation a wide range of options are available.
You probably already guessed this bit.
The c3
package is intended to be as simple and
lightweight as possible. As a starting point the data input must be a
data.frame
or tibble
with several options.
data.frame
without any options is passed all of
the numeric columns will be plotted. This can be used in line and bar
plots. Each column is a line or bar.x
, y
and group
. This requires a
data.frame
with a vertical structure.Where no options are supplied a simple line plot is produced by
default. Where no x-axis is defined the plots are sequential.
Date
x-axis can be parsed with not additional setting if in
the format %Y-%m-%d
(ie ‘2014-01-01’)
The package also imports the magrittr piping
function (%>%
) to simplify syntax.
There are 5 different line plots available:
Mixed geometry currently only works with a horizontal
data.frame
where each numeric column is plotted.
To use a secondary Y axis columns must first be matched to an axis and then the secondary axis made visible.
To highlight regions pass a single data.frame
with
columns axis
, start
, end
and
class
. Multiple regions can be defined within the one
data.frame
for any axis (x
, y
,
y2
). Each row in the data.frame
defines a
separate region to be highlighted
Plot color palettes can be changed to either
RColorBrewer
or viridis
palettes using either
RColorBrewer
(S3 method) or c3_viridus
.
Onclick, onmouseover and onmouseout are all available via the
c3
function. To use wrap a js function as a character
string to htmlwidgets::JS()
. Please see the C3.js
documentation and examples. The example
below should be enough to get you started.
C3
tooltips are readily modified with the use of
javascript functions. For further detail see the C3.js
documentation.
Or for more advanced usage see the C3.js
examples
page.