/
pictorial.Rmd
107 lines (87 loc) 路 2.02 KB
/
pictorial.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
---
title: "Pictorial"
author: "John Coene"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{John Coene}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
library(echarts4r)
e_common(
font_family = "Raleway"
)
```
Pictorial bar chart is a type of bar chart that custimzed glyph (like images, SVG PathData) can be used instead of rectangular bar. This kind of chart is usually used in infographic.
## Built-in symbols
```{r}
y <- rnorm(10, 10, 2)
df <- data.frame(
x = 1:10,
y = y,
z = y - rnorm(10, 5, 1)
)
df |>
e_charts(x) |>
e_bar(z, barWidth = 10) |>
e_pictorial(y, symbol = "rect", symbolRepeat = TRUE, z = -1,
symbolSize = c(10, 4)) |>
e_theme("westeros") |>
e_title("Built-in symbols")
```
## Icons
[echarts4r.assets](https://echarts4r-assets.john-coene.com) now includes icons you can easily include in your plots.
```{r}
library(echarts4r.assets)
mtcars |>
e_charts(mpg) |>
e_scatter(
wt,
qsec,
symbol = ea_icons("trash"),
name = "Trash"
) |>
e_legend(icons = ea_icons("trash"))
```
## SVG path
```{r}
path <- "path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z"
style <- list(
normal = list(opacity = 0.5), # normal
emphasis = list(opacity = 1) # on hover
)
df |>
e_charts(x) |>
e_pictorial(y, symbol = path,
barCategoryGap = "-130%",
itemStyle = style) |>
e_title("SVG path")
```
## Images
```{r}
qomo <- paste0(
"https://echarts.apache.org/examples/",
"data/asset/img/hill-Qomolangma.png"
)
kili <- paste0(
"https://echarts.apache.org/examples/",
"data/asset/img/hill-Kilimanjaro.png"
)
data <- data.frame(
x = c("Qomolangma", "Kilimanjaro"),
value = c(8844, 5895),
symbol = c(paste0("image://", qomo),
paste0("image://", kili))
)
data |>
e_charts(x) |>
e_pictorial(value, symbol) |>
e_legend(FALSE) |>
e_title("Images", "Mountains height")
```