First, you should load recharts
:
library(recharts)
setTheme
is the main aesthetic function in recharts. It can
All the function names have two forms: small camel and lowercase_underscore (endorsed by Hadley Wickham).
setTheme(chart, theme = c("asis", "default", "macarons", "infographic",
"blue", "dark", "gray", "green", "helianthus", "macarons2", "mint", "red",
"roma", "sakura", "shine", "vintage"), palette = "asis", bgColor = NULL,
renderAsImage = FALSE, calculable = FALSE, calculableColor = NULL,
calculableHolderColor = NULL, animation = TRUE, animationEasing = NULL,
animationDuration = NULL, width = NULL, height = NULL, ...)
set_theme(chart, theme = c("asis", "default", "macarons", "infographic",
"blue", "dark", "gray", "green", "helianthus", "macarons2", "mint", "red",
"roma", "sakura", "shine", "vintage"), palette = "asis", bgColor = NULL,
renderAsImage = FALSE, calculable = FALSE, calculableColor = NULL,
calculableHolderColor = NULL, animation = TRUE, animationEasing = NULL,
animationDuration = NULL, width = NULL, height = NULL, ...)
Arg | Requirement |
---|---|
chart |
Echarts object generated by |
theme |
theme name or theme object
|
palette |
name of the palette or a color vector. Default NULL to get echarts default.
Usage
|
bgColor |
Color name/value of the background. Default is transparent (‘rgba(0,0,0,0)’) |
renderAsImage |
Logical. If TRUE, the interactive effects are disabled. Default FALSE. |
calculable |
Logical. If TRUE, the chart is re-calculated after drag. Default FALSE. |
calculableColor |
The border color of the tooltip during calculable effect. Default ‘rgba(255,165,0,0.6)’. |
calculableHolderColor |
The color of calculableHolder. Default ‘#ccc’. |
animation |
Logical. If TRUE, the animation is on at initiation. Default TRUE. For IE8, it is recommended to set FALSE. |
animationEasing |
The slight moving effect of major elements. Default ‘ExponentialOut’. Other choices: ‘Linear’, ‘QuadraticIn’, ‘QuadraticOut’, ‘QuadraticInOut’, ‘CubicIn’, ‘CubicOut’, ‘CubicInOut’, ‘QuarticIn’, ‘QuarticOut’, ‘QuarticInOut’, ‘QuinticIn’, ‘QuinticOut’, ‘QuinticInOut’, ‘SinusoidalIn’, ‘SinusoidalOut’, ‘SinusoidalInOut’, ‘ExponentialIn’, ‘ExponentialInOut’, ‘CircularIn’, ‘CircularOut’, ‘CircularInOut’, ‘ElasticIn’, ‘ElasticOut’, ‘ElasticInOut’, ‘BackIn’, ‘BackOut’, ‘BackInOut’, ‘BounceIn’, ‘BounceOut’, ‘BounceInOut’ |
animationDuration |
The duration into animation. Default 2000 (ms). |
width |
Width (px) of the whole chart. Default NULL (auto). |
height |
Height (px) of the whole chart. Default NULL (auto). |
… |
Elipsis |
You can design your prefered themes using http://echarts.baidu.com/echarts2/doc/example/themeDesigner.html.
The UDTs in echarts are JS objects. You can write it in a list form and setTheme will parse it into JSON string for process.
A typical theme JS looks like:
{
color: ['#ff7f50','#87cefa','#da70d6','#32cd32','#6495ed'],
title: {x: 'left', y: 'top'},
legend: {orient: 'horizontal'}
}
You should write in the format below:
list(
color=c('#ff7f50','#87cefa','#da70d6','#32cd32','#6495ed'),
title=list(x='left', y='top'),
legend=list(orient='horizontal')
)
g <- echartr(mtcars, wt, mpg, carb, weight=hp, z=am, type='bubble') %>%
setSymbols('circle')
g
g %>% setTheme('macarons')
g %>% setTheme('infographic')
g %>% setTheme('blue')
g %>% setTheme('dark')
g %>% setTheme('gray')
g %>% setTheme('green')
g %>% setTheme('helianthus')
g %>% setTheme('macarons2')
g %>% setTheme('mint')
g %>% setTheme('red')
g %>% setTheme('roma')
g %>% setTheme('sakura')
g %>% setTheme('shine')
g %>% setTheme('vintage')
Let’s compose a UDT.
udt <- list(
backgroundColor="#d5e4eb", grid=list(borderWidth=0),
categoryAxis=list(axisLine=list(lineStyle=list(width=2)),
splitLine=list(lineStyle=list(width=1, color='white'))),
valueAxis=list(splitLine=list(lineStyle=list(width=1, color='white')),
axisLine=list(lineStyle=list(width=0)))
)
g %>% setXAxis(splitLine=list(show=FALSE)) %>% setTheme(udt)
All the pre-installed theme contain a palette. If you do not apply all the sytles of the theme, you can assign palette='_theme name'
. Remember to add a “_" in front of the theme name.
g %>% setTheme(palette="_dark")
RColorBrewer
PalettesYou can also assign RColorBrewer
palettes: ‘BrBG’, ‘PiYG’, ‘PRGn’, ‘PuOr’, ‘RdBu’, ‘RdGy’, ‘RdYlBu’, ‘RdYlGn’, ‘Spectral’, ‘Accent’, ‘Dark2’, ‘Paired’, ‘Pastel1’, ‘Pastel2’, ‘Set1’, ‘Set2’, ‘Set3’, ‘Blues’, ‘BuGn’, ‘BuPu’, ‘GnBu’, ‘Greens’, ‘Greys’, ‘Oranges’, ‘OrRd’, ‘PuBu’, ‘PuBuGn’, ‘PuRd’, ‘Purples’, ‘RdPu’, ‘Reds’, ‘YlGn’, ‘YlGnBu’, ‘YlOrBr’, ‘YlOrRd’.
g %>% setTheme(palette='PRGn')
ggthemes
PalettesYou can assign ggthemes
palettes: ‘calc’, ‘economist’, ‘economist_white’, ‘economist_stata’, ‘excel’, ‘exel_fill’, ‘excel_line’, ‘excel_new’, ‘few’, ‘fivethirtyeight’, ‘538’, ‘manyeyes’, ‘gdocs’, ‘pander’, ‘tableau’, ‘stata’, ‘stata1’,‘stata1r’,‘statamono’, ‘ptol’, ‘tableau20’, ‘tableau10medium’, ‘tableaugray’, ‘tableauprgy’, ‘tableaublrd’, ‘tableaugnor’, ‘tableaucyclic’, ‘tableau10light’, ‘tableaublrd12’, ‘tableauprgy12’, ‘tableaugnor12’,‘hc’,‘darkunica’, ‘solarized’,‘solarized_red’, ‘solarized_yellow’, ‘solarized_orange’, ‘solarized_magenta’, ‘solarized_violet’, ‘solarized_blue’, ‘solarized_cyan’, ‘solarized_green’, ‘wsj’, ‘wsj_rgby’, ‘wsj_red_green’, ‘wsj_black_green’, ‘wsj_dem_rep’, ‘colorblind’, ‘trafficlight’.
g %>% setTheme(palette='tableau20')
You can assign other palettes: ‘rainbow’, ‘terrain’, ‘topo’, ‘heat’, ‘cm’.
g %>% setTheme(palette='terrain')
You can also compose a palette by concatenating a vector of colors yourself. E.g.:
g %>% setTheme(palette=c(
'red', 'yellow', 'orange', 'limegreen', 'cyan', 'violet'))
bgColor
g %>% setTheme(bgColor='darkblue')
renderAsImage
Disable the interactive effects.
g %>% setTheme(renderAsImage=TRUE)
calculable
Use pie chart for example. Try dragging a fan away.
echartr(mtcars, am, hp, type='ring') %>%
setTheme(calculable=TRUE, calculableColor='yellow',
calculableHolderColor='gold')
animation
g %>% setTheme(animation=TRUE, animationEasing='BounceInOut',
animationDuration=500)
width
And height
g %>% setTheme(width=400, height=300)
theme
http://echarts.baidu.com/echarts2/doc/example/theme.html
backgroundColor
http://echarts.baidu.com/echarts2/doc/option.html#title~backgroundColor
colors
http://echarts.baidu.com/echarts2/doc/option.html#title~color
http://colorbrewer2.org
other features
http://echarts.baidu.com/echarts2/doc/option.html#title~renderAsImage
http://echarts.baidu.com/echarts2/doc/option.html#title~calculable
http://echarts.baidu.com/echarts2/doc/option.html#title~animation
http://echarts.baidu.com/echarts2/doc/option.html#title~calculableColor
http://echarts.baidu.com/echarts2/doc/option.html#title~calculableHolderColor