-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtitles-tooltips.Rmd
More file actions
74 lines (55 loc) · 1.22 KB
/
titles-tooltips.Rmd
File metadata and controls
74 lines (55 loc) · 1.22 KB
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
---
title: Titles and Tooltips
---
```{r}
library(gglite)
```
## Chart Title
### Title and subtitle via `g2()` arguments
```{r}
g2(mtcars, x = 'mpg', y = 'hp',
title = 'Motor Trend Cars', subtitle = 'mpg vs horsepower')
```
### Simple title
```{r}
g2(mtcars, x = 'mpg', y = 'hp') |>
title_('Motor Trend Cars')
```
### Title with subtitle
```{r}
g2(mtcars, x = 'mpg', y = 'hp') |>
title_('Motor Trend Cars', subtitle = 'mpg vs horsepower')
```
### Title alignment
```{r}
g2(mtcars, x = 'mpg', y = 'hp') |>
title_('Right-aligned Title', align = 'right')
```
### Title on a bar chart
```{r}
df = data.frame(x = c('A', 'B', 'C', 'D'), y = c(3, 7, 2, 5))
g2(df, x = 'x', y = 'y') |>
mark_interval() |>
title_('Simple Bar Chart', subtitle = 'Categories A-D')
```
## Tooltip Configuration
### Enable crosshairs
```{r}
g2(mtcars, x = 'mpg', y = 'hp') |>
tooltip_(crosshairs = TRUE)
```
### Shared tooltip (useful for multi-series)
```{r}
df = data.frame(
x = rep(1:5, 2), y = c(3, 1, 4, 1, 5, 2, 7, 1, 8, 3),
group = rep(c('A', 'B'), each = 5)
)
g2(df, x = 'x', y = 'y', color = 'group') |>
mark_line() |>
tooltip_(shared = TRUE)
```
### Disable tooltip
```{r}
g2(mtcars, x = 'mpg', y = 'hp') |>
tooltip_(FALSE)
```