First, you should load recharts:

library(recharts)

1 Introduction

The basic framework to make an Echarts object is

Step 1 echart => Step 2 set[Widgets] => Step 3 set[Aesthetics]. 

Step 1 makes the structure of the Echarts object, step 2 creates/modifies its widgets, and step 3 modifies the params of the widgets. But what if you want to modify the details inside the series list? – You may want setSeries.

setSeries is a bit low-level, compared to other set[Widgets] functions. It directly passes the param list on to an Echarts object and may lead to unexpected results. So you are suggested to get more familiar with Echarts structure before you decide to setSeries.

2 Function Call

setSeries(chart, series = NULL, timeslots = NULL, ...)
Arg Requirement

chart

Echarts object generated by echartR or echart.

series

series, could be the name or the index of the series. When the string is not in the existing series list, it will be treated as new. If set NULL, the function applies to all the series.

timeslots

vector of timeslots, either name or index of timeline variable z. If set NULL, the function applies to all the timeslots.

Elipsis, containing the params to pass to the echarts object for modification.

2.1 Generic Features in Elipsis

Feature Interpretation

type

chart type. ‘line’, ‘bar’, ‘scatter’, ‘k’, ‘pie’, ‘radar’, ‘chord’, ‘force’, ‘map’… If NULL, the series will not display.

name

name of the series.

tooltip

setTooltip

data

the data part of echartR

itemStyle

itemStyle

markPoint

addMarkPoint

markLine

addMarkLine

clickable

whether the data graph is clickable, default TRUE.

z

level-2 layer control, default 2.

zlevel

level-1 layer control, default 0.

2.2 Chart-type-specific Features in Elipsis

2.2.1 Line/Area

Feature Interpretation

stack

TRUE/FALSE

xAxisIndex

0/1, default 0 (main axis)

yAxisIndex

0/1, default 0 (main axis)

symbol

setSymbols

symbolSize

numeric or JS function

symbolRotate

-180 ~ 180

showAllSymbol

TRUE/FALSE, default FALSE

smooth

TRUE/FALSE, default FALSE

dataFilter

only for line charts. ‘nearest’/‘min’/‘max’/‘average’, default ‘nearest’.

legendHoverLink

TRUE/FALSE, default TRUE.

2.2.2 Bar/Column/Histogram

Feature Interpretation

stack

TRUE/FALSE

xAxisIndex

0/1, default 0 (main axis)

yAxisIndex

0/1, default 0 (main axis)

barGap

percent or numeric, default ‘30%’.

barCategoryGap

percent or numeric, default ‘20%’.

barMinHeight

numeric, default 0.

barWidth

numeric, default automatic.

barMaxWidth

numeric, default automatic.

legendHoverLink

TRUE/FALSE, default TRUE.

2.2.3 Scatter/Bubble

Feature Interpretation

xAxisIndex

0/1, default 0 (main axis)

yAxisIndex

0/1, default 0 (main axis)

symbol

setSymbols

symbolSize

numeric or JS function

symbolRotate

-180 ~ 180

large

TRUE/FALSE, default FALSE.

largeThreshold

numeric, default 2000.

legendHoverLink

TRUE/FALSE, default TRUE.

2.2.4 Pie/Ring/Rose

Feature Interpretation

legendHoverLink

TRUE/FALSE, default TRUE.

center

percent or numeric, default c(‘50%’, ‘50%’)

radius

percent or numeric, default c(0, ‘75%’)

startAngle

numeric -360 ~ 360, default 90 for pie.

minAngle

numeric, default 0.

clockWise

TRUE/FALSE, default TRUE.

roseType

‘radius’/‘area’.

selectedOffset

numeric, default 10.

selectedMode

NULL/‘single’/‘multiple’, default NULL.

2.2.5 Radar

Feature Interpretation

symbol

setSymbols

symbolSize

numeric or JS function

symbolRotate

-180 ~ 180

legendHoverLink

TRUE/FALSE, default TRUE.

polarIndex

numeric. Index of the polar system to host the series.

2.2.6 Chord

Feature Interpretation

symbol

setSymbols

symbolSize

numeric or JS function

clockWise

TRUE/FASLE, default FALSE.

categories

character vector

links

list of links

matrix

matrix data

minRadius

numeric, default 10.

maxRadius

numeric, default 20.

ribbonType

TRUE/FALSE, default TRUE.

showScale

TRUE/FALSE, default FALSE.

showScaleText

TRUE/FALSE, default FALSE

padding

numeric, default 2.

sort

‘none’/‘ascending’/‘descending’, default ‘none’.

sortSub

‘none’/‘ascending’/‘descending’, default ‘none’.

nodes

nodes list

2.2.7 Force

Feature Interpretation

symbol

setSymbols

symbolSize

numeric or JS function.

large

TRUE/FALSE, default FALSE.

center

percent or numeric, default c(‘50%’, ‘50%’).

roam

TRUE/FALSE/‘scale’/‘move’, default FALSE.

categories

character vector

links

links list

matrix

data matrix

size

percent or numeric, default ‘100%’

minRadius

numeric, default 10.

maxRadius

numeric, default 20.

linkSymbol

vector of symbol characters, default c(‘none’, ‘arrow’)

linkSymbolSize

numeric verctor, default c(10, 15)

scaling

numeric, default 1

gravity

numeric, default 1

draggable

TRUE/FALSE, default TRUE

useWorker

TRUE/FALSE, default FALSE

steps

numeric, default 1

nodes

nodes list

2.2.8 Map

Feature Interpretation

selectedMode

NULL/‘single’/‘multiple’, default NULL

mapType

‘china’/‘world’, default ‘china’

hoverable

TRUE/FALSE, default TRUE

dataRangeHoverLink

TRUE/FALSE, default TRUE

mapLocation

list(x=.., y=.., width=.., height=..), default list(x='center', y='center')

mapValueCalculation

‘sum’/‘average’, default ‘sum’

mapValuePrecision

integer, default 0

showLegendSymbol

TRUE/FALSE, default TRUE

roam

TRUE/FALSE/‘scale’/‘move’, default FALSE

scaleLimit

numeric list(max=.., min=..), default NULL

nameMap

addNameMap

textFixed

list, e.g., list(China=c(10, -10)), default NULL

geoCoord

addGeoCoord

heatmap

addHeatMap

2.2.9 Gauge

Feature Interpretation

legendHoverLink

TRUE/FALSE, default TRUE.

center

percent or numeric vector, default c(‘50%’, ‘50%’)

radius

percent or numeric vector, default c(0, ‘75%’)

startAngle

numeric -360 ~ 360, default 225

endAngle

numeric -360 ~ 360, default -45

min

numeric, default 0

max

numeric, default 100

splitNumber

numeric, default 10

axisLine

list, default list( show=TRUE, lineStyle=list(color``=list(list(0.2, '#228b22'), list(0.8, '#48b'), list(1, '#ff4500')), width=30))

axisTick

list, default list( show=TRUE, splitNumber=5, length=8, lineStyle=list( color='#eee', width=1, type='solid'))

axisLabel

list, default list(show=TRUE, formatter=NULL, textStyle=list(color='auto'))

splitLine

list, default list(show=TRUE, length=30, lineStyle=list( color='#eee', width=2, type='solid'))

pointer

list, default list(length='80%', width=8, color='auto')

title

list, default list(show=TRUE, offsetCenter=list(0, '40%'), textStyle=list(color='#333', fontSize=15))

detail

list, default list(show=TRUE, backgroundColor='rgba(0,0,0,0)', borderWidth=0, borderColor='#ccc', width=100, height=40, offsetCenter=list(0, '40%'), formatter=NULL, textStyle=list(color='auto', fontSize=30))

2.2.10 Funnel

Feature Interpretation

legendHoverLink

TRUE/FALSE, default TRUE.

sort

‘ascending’|‘descending’, default ‘descending’

min

numeric, default 0

max

numeric, default 100

x

numeric, default 80

y

numeric, default 60

x2

numeric, default 80

y2

numeric, default 60

width

percent or numeric, default NULL

height

percent or numeric, default NULL

funnelAlign

‘left’/‘right’/‘center’, default ‘center’

minSize

percent, default ‘0%’

maxSize

percent, default ‘100%’

gap

numeric, default 0

2.2.11 eventRiver

Feature Interpretation

xAxisIndex

0/1, default 0 (main axis)

legendHoverLink

TRUE/FALSE, default TRUE.

weight

numeric, default 1

2.2.12 Treemap

Feature Interpretation

center

percent or numeric vector, default c(‘50%’, ‘50%’)

size

percent or numeric vector, default c(‘80%’, ‘80%’)

root

name of the root displayed currently

2.2.13 Tree

Feature Interpretation

symbol

setSymbols

symbolSize

numeric or JS function.

roam

TRUE/FALSE/‘scale’/‘move’, default FALSE

rootLocation

list, could be list(x='center' / 'left' / 'right' / 'x%' / number, y='center' / 'top' / 'bottom' / 'y%' / number)

layerPadding

numeric, default 100

nodePadding

numeric, default 30

orient

‘vertical’/‘horizontal’/‘radial’, default ‘vertical’

direction

“” or “inverse”, default “”

2.2.14 wordCloud

Feature Interpretation

center

percent or numeric vector, default c(‘50%’, ‘50%’)

size

percent or numeric vector, default c(‘80%’, ‘80%’)

textRotation

vector, -90 ~ 90, default c(0, 90)

autoSize

list, default list(enable=TRUE, minSize=12)

2.2.15 Heatmap

Feature Interpretation

blurSize

numeric, default 30

gradientColors

list(offset=.., color=..) or color vector. default list('blue', 'cyan', 'limegreen', 'yellow', 'red')

minAlpha

numeric, default 0.05

valueScale

numeric, default 1

opacity

numeric, default 1

3 Showcase

3.1 Data Preparation

Let’s use airquality to generate 4 Echarts objects g1 - g4:

timeline mono series multi series
no g1 g2
yes g3 g4
require(data.table)
## Loading required package: data.table
aq <- airquality
aq$Date <- as.Date(paste('1973', aq$Month, aq$Day, sep='-'))
g1 <- echartr(aq, Date, Temp, type='curve') %>% setToolbox(pos=3)
g2 <- echartr(aq, Day, Temp, Month, type='curve') %>% setToolbox(pos=3)
g3 <- echartr(aq, Day, Temp, t=Month, type='curve') %>% setToolbox(pos=3)
aq1 <- melt(aq, id=c('Month', 'Day'), measure=c('Temp', 'Wind'), 
            variable='Param')
g4 <- echartr(aq1, Day, value, Param, t=Month, type='curve') %>% 
    setToolbox(pos=3)

3.2 Modification

setSeries can modify everything within series.

You can change chart type and THEN tune the new graph features.

g1 %>% setSeries(type='bar') %>% setSeries(barWidth=0.5)

You can limit the modification in some certain series…

g2 %>% setSeries(series='5', itemStyle=list(normal=itemStyle(
    lineStyle=lineStyle(shadowBlur=10, shadowColor='yellow')))

or timeslots…

But the features tend to inherit by timeslot, so you need to reset the features on the following timeslot to block the inheritibility.

g3 %>% setSeries(timeslots='5', itemStyle=list(normal=itemStyle(
    lineStyle=lineStyle(shadowBlur=10, shadowColor='yellow')))) %>%
    setSeries(timeslots='6', itemStyle=list(normal=itemStyle(
    lineStyle=lineStyle(shadowBlur=0))))

or combination of series and timeslots.

g4 %>% setSeries(series='Temp', timeslots='5', itemStyle=list(normal=itemStyle(
    lineStyle=lineStyle(shadowBlur=10, shadowColor='yellow')))) %>%
    setSeries(timeslots='6', series='Temp', itemStyle=list(normal=itemStyle(
        lineStyle=lineStyle(shadowBlur=0)
    )))