First, you should load recharts
:
library(recharts)
aesStyle
is a big family to construct Echarts styling element objects. E.g., Echarts uses itemStyle
heavily, and you can either use itemStyle
function or directly build the itemStyle object by writing a list.
Inside an itemStyle list object, there are three types of elements:
All the function names have two forms: small camel and lowercase_underscore (endorsed by Hadley Wickham). To be lazy, we also provide short forms as well (e.g., ll for labelLine).
aesStyle(element = c("text", "line", "area", "chord", "node", "link"), ...)
aes_style(element = c("text", "line", "area", "chord", "node", "link"), ...)
lineStyle(...)
style_line(...)
textStyle(...)
style_text(...)
areaStyle(...)
style_area(...)
chordStyle(...)
style_chord(...)
nodeStyle(...)
style_node(...)
linkStyle(...)
style_link(...)
labelStyle(...)
style_label(...)
labelLineStyle(...)
style_labelline(...)
style_ll(...)
itemStyle(...)
style_item(...)
Arg | Requirement |
---|---|
chart |
Echarts object generated by |
element |
c(“text”, “line”, “area”, “chord”, “node”, “link”). |
… |
The params to form an aesthetic element. |
itemStyle
(normal|emphasis)Arg | Instruction |
---|---|
color | color vector, ‘rgba’, hex color, or color names. |
lineStyle | for line, k charts and markLine, see lineStyle |
textStyle | see textStyle |
areaStyle | for stacked line chart and map, see areaStyle |
chordStyle | for chord chart, see chordStyle |
nodeStyle | for force chart, see nodeStyle |
linkStyle | for force chart, see linkStyle |
borderColor | color vector, ‘rgba’, hex color, or color names. |
borderWidth | for symbol, symbole, pie chart, map and markPoint, numeric |
barBorderColor | for symbol, symbole, pie chart, map and markPoint, numeric |
barBorderRadius | numeric vector length 1 or 4 (right-bottom-left-top), default 0 |
barBorderWidth | numeric vector length 1 or 4 (right-bottom-left-top), default 00 |
label | for line, bar, k, scatter, pie, map, force, funnel charts and markPoint, markLine, see labelStyle |
labelLine | for pie and funnel chart, see labelLineStyle |
labelStyle
/ style_label
Arg | Instruction |
---|---|
show |
TRUE|FALSE, default TRUE |
position |
|
rotate |
chord chart only. TRUE|FALSE, default FALSE |
distance |
chord and pie chart only. numeric, default 10 |
formatter |
see |
textStyle |
see |
x |
treemap only, numeric |
y |
treemap only, numeric |
labelLineStyle
/ style_ll
/ style_labelline
Arg | Instruction |
---|---|
show | TRUE |
length | numeric or ‘auto’, default 40 |
lineStyle | see lineStyle |
textStyle
/ style_text
Arg | Instruction |
---|---|
color | color vector, ‘rgba’, hex color, or color names. |
decoration | only for tooltip. string, default ‘none’ |
align | ‘left’ / ‘right’ / ‘center’ |
baseline | ‘top’ / ‘bottom’ / ‘middle’ |
fontFamily | valid font family name |
fontSize | numeric, default 12 |
fontStyle | ‘normal’ / ‘italic’ / ‘oblique’, default ‘normal’ |
fontWeight | ‘normal’ / ‘bold’ / ‘bolder’ / ‘lighter’ or numeric, default ‘normal’ |
lineStyle
/ style_line
Arg | Instruction |
---|---|
color | color vector, ‘rgba’, hex color, or color names. |
type | ‘solid’ / ‘dotted’ / ‘dashed’, for tree, additionally ‘curve’ / ‘broken’. Default ‘solid’ |
width | numeric |
shadowColor | color vector, ‘rgba’, hex color, or color names. |
shadowBlur | numeric, default 5 |
shadowOffsetX | numeric, default 3 |
shadowOffsetY | numeric, default 3 |
areaStyle
/ style_area
Arg | Instruction |
---|---|
color | color vector, ‘rgba’, hex color, or color names. |
type | only ‘default’ |
chordStyle
/ style_chord
Arg | Instruction |
---|---|
width | numeric, default 1 |
color | color vector, ‘rgba’, hex color, or color names. |
borderWidth | numeric, default 1 |
borderColor | color vector, ‘rgba’, hex color, or color names. |
nodeStyle
/ style_node
Arg | Instruction |
---|---|
color | color vector, ‘rgba’, hex color, or color names. |
borderWidth | numeric, default 1 |
borderColor | color vector, ‘rgba’, hex color, or color names. |
linkStyle
/ style_link
Arg | Instruction |
---|---|
type | ‘curve’ |
color | color vector, ‘rgba’, hex color, or color names. default ‘#5182ab’ |
width | numeric, default 1 |
How to build an itemStyle object?
First, build the low-level style element object.
styText <- textStyle(color='red', fontFamily='Arial')
styLine <- lineStyle(color='#fff', width=4, shadowBlur=5)
Then, build up higher-level style element objects.
lab <- labelStyle(show=TRUE, position='inside', textStyle=styText)
Finally, consolidate an itemSytle object.
itemStyle <- list(normal=itemStyle(lineStyle=styLine, label=lab),
emphasis=itemStyle(lineStyle=styLine, label=lab)
)