First, you should load recharts
:
library(recharts)
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
.
setSeries(chart, series = NULL, timeslots = NULL, ...)
Arg | Requirement |
---|---|
chart |
Echarts object generated by |
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 |
… |
Elipsis, containing the params to pass to the echarts object for modification. |
Feature | Interpretation |
---|---|
|
chart type. ‘line’, ‘bar’, ‘scatter’, ‘k’, ‘pie’, ‘radar’, ‘chord’, ‘force’, ‘map’… If NULL, the series will not display. |
|
name of the series. |
|
|
|
the data part of |
|
|
|
|
|
|
|
whether the data graph is clickable, default TRUE. |
|
level-2 layer control, default 2. |
|
level-1 layer control, default 0. |
Feature | Interpretation |
---|---|
|
TRUE/FALSE |
|
0/1, default 0 (main axis) |
|
0/1, default 0 (main axis) |
|
|
|
numeric or JS function |
|
-180 ~ 180 |
|
TRUE/FALSE, default FALSE |
|
TRUE/FALSE, default FALSE |
|
only for line charts. ‘nearest’/‘min’/‘max’/‘average’, default ‘nearest’. |
|
TRUE/FALSE, default TRUE. |
Feature | Interpretation |
---|---|
|
TRUE/FALSE |
|
0/1, default 0 (main axis) |
|
0/1, default 0 (main axis) |
|
percent or numeric, default ‘30%’. |
|
percent or numeric, default ‘20%’. |
|
numeric, default 0. |
|
numeric, default automatic. |
|
numeric, default automatic. |
|
TRUE/FALSE, default TRUE. |
Feature | Interpretation |
---|---|
|
0/1, default 0 (main axis) |
|
0/1, default 0 (main axis) |
|
|
|
numeric or JS function |
|
-180 ~ 180 |
|
TRUE/FALSE, default FALSE. |
|
numeric, default 2000. |
|
TRUE/FALSE, default TRUE. |
Feature | Interpretation |
---|---|
|
TRUE/FALSE, default TRUE. |
|
percent or numeric, default c(‘50%’, ‘50%’) |
|
percent or numeric, default c(0, ‘75%’) |
|
numeric -360 ~ 360, default 90 for pie. |
|
numeric, default 0. |
|
TRUE/FALSE, default TRUE. |
|
‘radius’/‘area’. |
|
numeric, default 10. |
|
NULL/‘single’/‘multiple’, default NULL. |
Feature | Interpretation |
---|---|
|
|
|
numeric or JS function |
|
-180 ~ 180 |
|
TRUE/FALSE, default TRUE. |
|
numeric. Index of the polar system to host the series. |
Feature | Interpretation |
---|---|
|
|
|
numeric or |
|
TRUE/FASLE, default FALSE. |
|
character vector |
|
list of links |
|
matrix data |
|
numeric, default 10. |
|
numeric, default 20. |
|
TRUE/FALSE, default TRUE. |
|
TRUE/FALSE, default FALSE. |
|
TRUE/FALSE, default FALSE |
|
numeric, default 2. |
|
‘none’/‘ascending’/‘descending’, default ‘none’. |
|
‘none’/‘ascending’/‘descending’, default ‘none’. |
|
nodes list |
Feature | Interpretation |
---|---|
|
|
|
numeric or |
|
TRUE/FALSE, default FALSE. |
|
percent or numeric, default c(‘50%’, ‘50%’). |
|
TRUE/FALSE/‘scale’/‘move’, default FALSE. |
|
character vector |
|
links list |
|
data matrix |
|
percent or numeric, default ‘100%’ |
|
numeric, default 10. |
|
numeric, default 20. |
|
vector of symbol characters, default c(‘none’, ‘arrow’) |
|
numeric verctor, default c(10, 15) |
|
numeric, default 1 |
|
numeric, default 1 |
|
TRUE/FALSE, default TRUE |
|
TRUE/FALSE, default FALSE |
|
numeric, default 1 |
|
nodes list |
Feature | Interpretation |
---|---|
|
NULL/‘single’/‘multiple’, default NULL |
|
‘china’/‘world’, default ‘china’ |
|
TRUE/FALSE, default TRUE |
|
TRUE/FALSE, default TRUE |
|
|
|
‘sum’/‘average’, default ‘sum’ |
|
integer, default 0 |
|
TRUE/FALSE, default TRUE |
|
TRUE/FALSE/‘scale’/‘move’, default FALSE |
|
numeric |
|
|
|
list, e.g., |
|
|
|
|
Feature | Interpretation |
---|---|
|
TRUE/FALSE, default TRUE. |
|
percent or numeric vector, default c(‘50%’, ‘50%’) |
|
percent or numeric vector, default c(0, ‘75%’) |
|
numeric -360 ~ 360, default 225 |
|
numeric -360 ~ 360, default -45 |
|
numeric, default 0 |
|
numeric, default 100 |
|
numeric, default 10 |
|
list, default |
|
list, default |
|
list, default |
|
list, default |
|
list, default |
|
list, default |
|
list, default |
Feature | Interpretation |
---|---|
|
TRUE/FALSE, default TRUE. |
|
‘ascending’|‘descending’, default ‘descending’ |
|
numeric, default 0 |
|
numeric, default 100 |
|
numeric, default 80 |
|
numeric, default 60 |
|
numeric, default 80 |
|
numeric, default 60 |
|
percent or numeric, default NULL |
|
percent or numeric, default NULL |
|
‘left’/‘right’/‘center’, default ‘center’ |
|
percent, default ‘0%’ |
|
percent, default ‘100%’ |
|
numeric, default 0 |
Feature | Interpretation |
---|---|
|
0/1, default 0 (main axis) |
|
TRUE/FALSE, default TRUE. |
|
numeric, default 1 |
Feature | Interpretation |
---|---|
|
percent or numeric vector, default c(‘50%’, ‘50%’) |
|
percent or numeric vector, default c(‘80%’, ‘80%’) |
|
name of the root displayed currently |
Feature | Interpretation |
---|---|
|
|
|
numeric or JS function. |
|
TRUE/FALSE/‘scale’/‘move’, default FALSE |
|
list, could be |
|
numeric, default 100 |
|
numeric, default 30 |
|
‘vertical’/‘horizontal’/‘radial’, default ‘vertical’ |
|
“” or “inverse”, default “” |
Feature | Interpretation |
---|---|
|
percent or numeric vector, default c(‘50%’, ‘50%’) |
|
percent or numeric vector, default c(‘80%’, ‘80%’) |
|
vector, -90 ~ 90, default c(0, 90) |
|
list, default |
Feature | Interpretation |
---|---|
|
numeric, default 30 |
|
|
|
numeric, default 0.05 |
|
numeric, default 1 |
|
numeric, default 1 |
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)
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)
)))