-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy paththemes.Rmd
166 lines (138 loc) · 3.5 KB
/
themes.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
---
title: Themes
author: Joshua Kunst
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
description: >
Highcharts is very flexible for create or themes.
In Highcarter there are some predefined themes and some
functions to create your own or merge themes.
editor_options:
chunk_output_type: console
vignette: >
%\VignetteIndexEntry{Themes}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
<script>
$(document).ready(function(){
el = $(".page-header > h1")
icon = "paint-brush"
text = el.text()
text_new = "<span class=\"fa fa-" + icon + "\"></span> " + text
el.html(text_new)
}) ;
</script>
```{r, include=FALSE}
library(highcharter)
library(dplyr)
library(purrr)
library(stringr)
library(htmltools)
library(ggplot2)
```
Highcharts is very flexible for create or themes.
In Highcarter there are some predefined themes and some
functions to create your own or merge themes.
Let's start with a simple bar chart and see the default theme:
```{r}
library(highcharter)
library(dplyr)
data(diamonds, package = "ggplot2")
data <- count(diamonds, cut, color)
hc <- hchart(data, "column", hcaes(x = color, y = n, group = cut)) |>
hc_yAxis(title = list(text = "Cases")) |>
hc_title(text = "Diamonds Are Forever") |>
hc_subtitle(text = "Source: Diamonds data set") |>
hc_credits(enabled = TRUE, text = "http://jkunst.com/highcharter/") |>
hc_tooltip(sort = TRUE, table = TRUE) |>
hc_caption(text = "This is a caption text to show the style of this type of text")
hc
```
## Themes
Here you'll find the themes to change the look of your charts.
```{r, echo=FALSE, results='asis'}
themes <- help.search("theme", package = "highcharter")$matches
themes <- themes |>
tibble::as_tibble() |>
janitor::clean_names() |>
select(name, title) |>
distinct() |>
filter(str_detect(name, "hc_theme_*")) |>
filter(!name %in% c("hc_theme_merge", "hc_theme")) |>
mutate(title = str_replace(title, " theme for highcharts", "")) |>
arrange(name) |>
pull(name)
themes <- str_subset(themes, "spark", negate = TRUE)
themes <- unique(c("hc_theme_smpl", "hc_theme_db", themes))
# thms <- sample(thms, 5)
# generate tabs
themes |>
map(function(t) { # t <- sample(themes, 1)
thm <- get(t)()
content <- list(hc) |>
map(hc_add_theme, thm) |>
dplyr::first()
tagList(
tags$h3(stringr::str_remove(t, "hc_theme_")),
content
)
}) |>
htmltools::as.tags()
```
## Creating themes
You can create your own themes!
```{r}
my_own_theme <- hc_theme(
colors = c("red", "green", "blue"),
chart = list(
backgroundColor = NULL,
divBackgroundImage = "http://media3.giphy.com/media/FzxkWdiYp5YFW/giphy.gif"
),
title = list(
style = list(
color = "#333333",
fontFamily = "Lato"
)
),
subtitle = list(
style = list(
color = "#666666",
fontFamily = "Shadows Into Light"
)
),
legend = list(
itemStyle = list(
fontFamily = "Tangerine",
color = "black"
),
itemHoverStyle = list(
color = "gray"
)
)
)
hc |>
hc_add_theme(my_own_theme)
```
## Merge Themes
You can merge themes too.
```{r}
thm <- hc_theme_merge(
hc_theme_darkunica(),
hc_theme(
chart = list(
backgroundColor = "transparent",
divBackgroundImage = "http://www.wired.com/images_blogs/underwire/2013/02/xwing-bg.gif"
),
title = list(
style = list(
color = "white",
fontFamily = "Griffy",
fontSize = "25px"
)
)
)
)
hc |>
hc_add_theme(thm)
```