-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.R
61 lines (48 loc) · 1.28 KB
/
functions.R
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
library(echarts4r)
library(tidyverse)
plot_bar <- function(df) {
measure <- df %>%
dplyr::ungroup() %>%
dplyr::select_if(is.numeric) %>%
names()
dimensions <- df %>%
dplyr::ungroup() %>%
dplyr::select(where(is.character), where(is.factor)) %>%
names()
if (length(measure) != 1) stop("Please supply a dataset with one measure")
plot <- df %>%
echarts4r::e_charts_(dimensions[1]) %>%
echarts4r::e_bar_(measure) %>%
echarts4r::e_tooltip() %>%
echarts4r::e_labels() %>%
echarts4r::e_x_axis(
axisLabel = list(
interval = 0,
rotate = 45,
width = 80,
overflow = "truncate"
)
)
return(plot)
}
plot_pie <- function(df) {
measure <- df %>%
dplyr::ungroup() %>%
dplyr::select_if(is.numeric) %>%
names()
dimensions <- df %>%
dplyr::ungroup() %>%
dplyr::select(where(is.character), where(is.factor)) %>%
names()
if (length(measure) != 1) stop("Please supply a dataset with one measure")
plot <- df %>%
echarts4r::e_charts_(dimensions[1]) %>%
echarts4r::e_pie_(measure, radius = c("40%", "70%")) %>%
echarts4r::e_tooltip() %>%
echarts4r::e_labels(
show = TRUE,
formatter = "{c}",
position = "inside"
)
return(plot)
}