Data helper

View source: R/util.R

ec.dataR Documentation

Data helper


Make data lists from a data.frame

Usage, format = "dataset", header = FALSE, ...)



Required chart data as data.frame.
Except when format is dendrogram, then df is a list, result of hclust function.


Output list format

  • dataset = list to be used in dataset (default), or in (without header).

  • values = list for customized

  • names = named lists useful for named data like sankey links.

  • dendrogram = build series data for Hierarchical Clustering dendrogram

  • treePC = build series data for tree charts from parent/children data.frame

  • treeTT = build series data for tree charts from data.frame like Titanic.

  • boxplot = build dataset and source lists, see Details


for dataset, to include the column names or not, default TRUE. Set it to FALSE for


optional parameters
Optional parameters for boxplot are:

  • layout = 'h' for horizontal(default) or 'v' for vertical layout

  • outliers boolean to add outlier points (default FALSE)

  • jitter value for jitter of numerical values in second column, default 0 (no scatter). Adds scatter series on top of boxplot.


format='boxplot' requires the first two df columns as:
⁠ ⁠column for the non-computational categorical axis
⁠ ⁠column with (numeric) data to compute the five boxplot values
Additional grouping is supported on a column after the second. Groups will show in the legend, if enabled.
Returns a list(dataset, series, xAxis, yAxis) to set params in ec.init. Make sure there is enough data for computation, 4+ values per boxplot.
format='treeTT' expects data.frame df columns pathString,value,(optional itemStyle) for FromDataFrameTable.
It will add column 'pct' with value percentage for each node. See Details.


A list for dataset.source, or other lists:
For boxplot - a named list, see Details and Examples
For dendrogram & treePC - a tree structure, see format in tree data

See Also

some live code samples


ds <- iris |> relocate(Species) |> 'boxplot', jitter= 0.1, layout= 'v')
  dataset= ds$dataset, series= ds$series, xAxis= ds$xAxis, yAxis= ds$yAxis,
  legend= list(show= TRUE), tooltip= list(show= TRUE)

hc <- hclust(dist(USArrests), "complete")
ec.init(preset= FALSE,
  series= list(list(
    type= 'tree', orient= 'TB', roam= TRUE, initialTreeDepth= -1,
    data=, format='dendrogram'),
    # layout= 'radial', symbolSize= ec.clmn(scale= 0.33),
    ## exclude added labels like 'pXX', leaving only the originals
    label= list(formatter= htmlwidgets::JS(
      "function(n) { out= /p\\d+/.test( ? '' :; return out;}"))

# build required pathString,value and optional itemStyle columns
df <- |> rename(value= Freq) |> mutate(
  pathString= paste('Titanic\nSurvival', Survived, Age, Sex, Class, sep='/'),
	 itemStyle= case_when(Survived=='Yes' ~"color='green'", TRUE ~"color='LightSalmon'")) |>
	 select(pathString, value, itemStyle)
	  series= list(list(
		  data=, format='treeTT'),
		  type= 'tree', symbolSize= ec.clmn("(x) => {return Math.log(x)*10}")
	  tooltip= list(formatter= ec.clmn('%@<br>%@%','value','pct'))

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