ec.data {echarty}R Documentation

Data helper

Description

Make data lists from a data.frame

Usage

ec.data(df, format = "dataset", header = TRUE)

Arguments

df

Chart data in data.frame format, required.
Except when format is 'dendrogram', then df is a list, result of hclust function.

format

A key on how to format the output list

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

  • 'values' = list for customized series.data

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

  • 'boxplot' = build dataset and source lists, see Details

  • 'dendrogram' = build series data for Hierarchical Clustering dendrogram

header

Boolean to include the column names in dataset, default TRUE.
Set this to FALSE when used in series.data.

Details

format='boxplot' requires the first two df columns as:

Grouped df is supported. Groups will show in the legend, if enabled.
Returns a list(dataset, series, axlbl) to set the chart. axlbl is a formatter for the category axis.
Make sure there is enough data for computation, like >4 values per boxplot. Otherwise ECharts may exit with a Object.transform error.

Value

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

See Also

some live code samples

Examples

library(dplyr)
#ds <- Orange |> relocate(age,circumference) |> ec.data(format='boxplot')
#ds <- Orange |> relocate(age,circumference) |> group_by(Tree) |> ec.data(format='boxplot')
#ds <- mtcars |> relocate(am,mpg) |> ec.data(format='boxplot')
 ds <- mtcars |> relocate(am,mpg) |> group_by(cyl) |> ec.data(format='boxplot')
p <- ec.init()
p$x$opts <- list(
  dataset= ds$dataset, 
  series=  ds$series, 
  yAxis= list(type= 'category',  # categorical yAxis = horizontal boxplots 
              axisLabel= list(formatter= ds$axlbl)),
  xAxis= list(show= TRUE),       # categorical xAxis = vertical boxplots 
  legend= list(show= TRUE)
)
p 

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


[Package echarty version 1.4.5 Index]