ec.init: Initialize command

View source: R/echarty.R

ec.initR Documentation

Initialize command

Description

Required to build a chart. In most cases this will be the only command necessary.

Usage

ec.init(
  df = NULL,
  preset = TRUE,
  ctype = "scatter",
  ...,
  series.param = NULL,
  tl.series = NULL,
  width = NULL,
  height = NULL
)

Arguments

df

A data.frame to be preset as dataset, default NULL
By default the first column is for X values, second column is for Y, and third is for Z when in 3D.
Best practice is to have the grouping column placed last. Grouping column cannot be used as axis.
Timeline requires a grouped data.frame to build its options.
If grouping is on multiple columns, only the first one is used to determine settings.

preset

Boolean (default TRUE). Build preset attributes like dataset, series, xAxis, yAxis, etc.

ctype

Chart type of series. Default is 'scatter'. Set to NULL to disable series preset.

...

List contains other attributes to pass to the widget.
Custom echarty widget attributes include:

  • elementId - Id of the widget, default is NULL(auto-generated)

  • load - name(s) of plugin(s) to load. A character vector or comma-delimited string. default NULL.

  • ask - prompt user before downloading plugins when load is present, FALSE by default

  • js - single string or a vector with JavaScript expressions to evaluate.
    single: exposed chart object (most common)
    vector:
    ⁠ ⁠First expression is evaluated before chart initialization.
    ⁠ ⁠Second is evaluated with exposed object opts.
    ⁠ ⁠Third is evaluated with exposed chart object after opts set.

  • renderer - 'canvas'(default) or 'svg'

  • locale - 'EN'(default) or 'ZH'. Use predefined or custom like so.

  • useDirtyRect - enable dirty rectangle rendering or not, FALSE by default, see here

series.param

Additional parameters for preset series, or NULL(default).
One can also define the complete series with series= list(list(...),...).

tl.series

A list to build a timeline or NULL(default). The list defines options series and their attributes.
The only required attribute is encode.
encode defines which data columns names to use for the axes:

  • set x and y for coordinateSystem cartesian2d

  • set lng and lat for coordinateSystem geo

  • set radius and angle for coordinateSystem polar

  • set value and itemName for pie chart

  • set value and name for map chart

Attribute coordinateSystem is not set by default and depends on chart type.
Custom attribute groupBy, a df column name, can create series groups inside each timeline step.
A grouped df must be present, with group column providing the timeline data. Auto-generated timeline and options will be preset for the chart.
tl.series cannot be used for hierarchical charts like graph,tree,treemap,sankey. Chart options/timeline have to be built directly, see example.

width, height

A valid CSS unit (like '100%', '500px', 'auto') or a number, which will be coerced to a string and have 'px' appended.

Details

Command ec.init creates a widget with createWidget, then adds some ECharts features to it.
When ec.init is chained after a data.frame, a dataset is preset.
When data.frame is grouped and ctype is not null, more datasets with legend and series are also preset.
Plugin '3D' presets will not work for 'scatterGL'. Instead, use preset=FALSE and set explicitly xAxis,yAxis.
Plugins 'leaflet' and 'world' preset zoom=6 and center to the mean of all coordinates.
Users can delete or overwrite any presets as needed.
Numerical indexes for series,visualMap,etc. are R-counted (1,2...)

Built-in plugins:

  • leaflet - Leaflet maps with customizable tiles, see source

  • world - world map with country boundaries, see source

  • lottie - support for lotties

  • custom - renderers for ecr.band and ecr.ebars
    Plugins with one-time installation:

  • 3D - 3D charts and WebGL acceleration, see source and docs

  • liquid - liquid fill, see source

  • gmodular - graph modularity, see source

  • wordcloud - cloud of words, see source
    or install your own third-party plugins.

Crosstalk:
Parameter df should be of type SharedData, see more info.
Optional parameter xtKey: unique ID column name of data frame df. Must be same as key parameter used in SharedData$new(). If missing, a new column XkeyX will be appended to df.
Enabling crosstalk will also generate an additional dataset called Xtalk and bind the first series to it.

Value

A widget to plot, or to save and expand with more features.

Examples

 # basic scatter chart from a data.frame, using presets
cars |> ec.init()
 
 # grouping, tooltips, formatting
iris |> dplyr::group_by(Species) |> 
ec.init(        # init with presets
  tooltip= list(show= TRUE),
  series.param= list( 
    symbolSize= ec.clmn(4, scale=7),
    tooltip= list(formatter= ec.clmn('Petal.Width: %@', 4))
  )
)


echarty documentation built on Oct. 16, 2023, 1:06 a.m.