Required to build a chart. In most cases this will be the only command necessary.
ec.init(
df = NULL,
preset = TRUE,
ctype = "scatter",
tl.series = NULL,
width = NULL,
height = NULL,
...
)
A widget to plot, or to save and expand with more features.
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.
For crosstalk df should be of type SharedData, see more info.
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.
Build preset xAxis,yAxis,serie for 2D, or grid3D,xAxis3D,yAxis3D,zAxis3D for 3D, default TRUE (enable).
Chart type of series. Default is 'scatter'. Set to NULL to disable series preset.
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.
A valid CSS unit (like '100%'
,
'500px'
, 'auto'
) or a number, which will be coerced to a
string and have 'px'
appended.
other arguments to pass to the widget.
Custom echarty widget arguments include:
elementId - Id of the widget, default is NULL(auto-generated)
load - name(s) of plugin(s) to load. Could be 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.
First expression is evaluated before chart initialization.
Second is evaluated with an exposed object opts.
Third is evaluated with an exposed chart object after opts have been 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
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 the data.frame is grouped and ctype is not null, more datasets with legend and series are also preset. Grouped series are preset as type scatter.
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.
ec.plugjs will be called internally for each load entry, popup prompts controlled by parameter ask.
Built-in plugins:
leaflet - Leaflet maps with customizable tiles, see source
custom - renderers for ecr.band and ecr.ebars
Plugins with one-time installation:
world - world map with country boundaries, see source
liquid - liquid fill, see source
gmodular - graph modularity, see source
wordcloud - cloud of words, see source
or install your own third-party plugins.
Package information in echarty-package.
# basic scatter chart from a data.frame, using presets
cars |> ec.init()
# a timeline with two series and autoPlay
p <- iris |> dplyr::group_by(Species) |> ec.init(
legend= list(show=TRUE),
tl.series= list(
encode=list(x=NULL, y=c('Sepal.Width', 'Petal.Length')),
markPoint = list(data=list(list(type='max'), list(type='min')))
)
) # |> ec.upd(...
p$x$opts$timeline <- append(p$x$opts$timeline, list(autoPlay=TRUE))
p
Run the code above in your browser using DataLab