First, you should load recharts
:
library(recharts)
Title comprises of two parts: title (and title link), subtitle (and subtitle link). The default position is 6 o’clock.
The recommended approach to use setTitle
is chart %>% setTitle(...)
.
All the function names have two forms: small camel and lowercase_underscore (endorsed by Hadley Wickham).
setTitle(chart, title = NULL, subtitle = NULL, link = NULL,
sublink = NULL, pos = 6, bgColor = NULL, borderColor = NULL,
borderWidth = NULL, textStyle = NULL, subtextStyle = NULL,
show = TRUE, ...)
set_title(chart, title = NULL, subtitle = NULL, link = NULL,
sublink = NULL, pos = 6, bgColor = NULL, borderColor = NULL,
borderWidth = NULL, textStyle = NULL, subtextStyle = NULL,
show = TRUE, ...)
Arg | Requirement |
---|---|
chart |
Echarts object generated by |
title |
text of the title. If written in markdown format |
subtitle |
text of the subtitle. If written in markdown format |
link |
link of the title |
sublink |
link of the subtitle |
pos |
the clock-position of title (and subtitle), refer to |
bgColor |
background color of title. Default ‘rgba(0,0,0,0)’ (transparent) |
borderColor |
border color of the title. Default ‘#ccc’. |
borderWidth |
border width of the title. Default 0px (not shown). |
textStyle |
You can place self-defined textStyle list of the title here. E.g., |
subtextStyle |
You can place self-defined textStyle of the subtitle here. |
show |
Logical. Whether to show the title. If you want to remove title from the echarts object, set it NULL. |
… |
Elipsis. |
g1 <- echartr(iris, Sepal.Width, Petal.Width, Species)
g2 <- echartr(iris, Sepal.Width, Petal.Width, t=Species)
|
|
Title and subtitle at the default position.
g1 %>% setTitle(title='Iris data set', subtitle='by: R. A. Fisher')
Relocate the title.
g1 %>% setTitle(title='Iris data set', subtitle='by: R. A. Fisher', pos=12)
Title and subtitle with links.
g1 %>% setTitle(
'[Iris data set](https://en.wikipedia.org/wiki/Iris_flower_data_set)',
'[R. A. Fisher](https://en.wikipedia.org/wiki/Ronald_Fisher)')
Customize the format (ugly).
g1 %>% setTitle(
'[Iris data set](https://en.wikipedia.org/wiki/Iris_flower_data_set)',
'[R. A. Fisher](https://en.wikipedia.org/wiki/Ronald_Fisher)',
textStyle=textStyle(fontFamily='Courier New', fontSize=24, color='gold'),
subtextStyle=textStyle(color='silver'), bgColor='lightgreen') %>%
setGrid(y2=90)
Title and subtitle at the default position.
g2 %>% setTitle(
'[Iris data set](https://en.wikipedia.org/wiki/Iris_flower_data_set)',
'[R. A. Fisher](https://en.wikipedia.org/wiki/Ronald_Fisher)')
Customierzed titles and subtitles. They must be written in vectors and will be then mapped to each timeslots along with the timeline.
titles <- c(
'[Iris setosa](https://en.wikipedia.org/wiki/Iris_setosa)',
'[Iris versicolor](https://en.wikipedia.org/wiki/Iris_versicolor)',
'[Iris virginica](https://en.wikipedia.org/wiki/Iris_virginica)')
g2 %>% setTitle(titles)
More settings on format. Elements such as textStyle should also be written in lists to map to each timeslots.
g2 %>% setTitle(
titles,
textStyle=list(
textStyle(fontFamily='Impact', color='red', fontStyle='normal'),
textStyle(fontFamily='Times New Roman', color='darkgreen'),
textStyle(fontFamily='Calibri', color='blue', fontStyle='oblique')
),
bgColor='yellow')