-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.qmd
More file actions
76 lines (56 loc) · 1.76 KB
/
Copy pathindex.qmd
File metadata and controls
76 lines (56 loc) · 1.76 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
75
---
title: "Interactive map"
format:
html:
code-fold: true
code-summary: "Show the code"
editor: visual
---
```{r}
library(ggplot2)
library(ggiraph)
library(patchwork)
# Example data - replace with your data
map_data <- data.frame(
id = 1:3,
lat = c(40, 42, 37),
lon = c(-100, -120, -95),
group = c("A", "B", "C")
)
line_data <- data.frame(
id = rep(1:3, each = 10),
time = rep(seq(as.Date("2021-01-01"), by = "1 month", length.out = 10), 3),
value = rnorm(30),
group = rep(c("A", "B", "C"), each = 10)
)
# Map with interactive points
map_plot <- ggplot() +
borders("world", colour = "gray80", fill = "gray90") + # Add a world map background
geom_point_interactive(data = map_data, aes(x = lon, y = lat, size = 5, color=group, tooltip = group, data_id = group)) +
theme_minimal() +
theme(legend.position = "none") +
coord_sf(xlim = c(-130, -65), ylim = c(10, 75))
# Line chart with interactive lines
line_plot <- ggplot(line_data, aes(x = time, y = value, group = group, color=group)) +
geom_line_interactive(aes(data_id = group, tooltip = group))
combined_plot <- girafe(
ggobj = map_plot + plot_spacer() + line_plot + plot_layout(widths = c(0.35, 0, 0.65)),
options = list(
opts_hover(css = ''),
opts_hover_inv(css = "opacity:0.1;"),
opts_sizing(rescale = FALSE)
),
height_svg = 4,
width_svg = 12
)
```
Let's say you have several samples in your dataset. Each coming from a different location.
You can use `ggiraph` to add a map, and link it with another way to visualize the data.
In the graph below, hover the map to reveal the sample evolution on the line chart!
<br/>
```{r}
combined_plot
```
<br/>
If you are interested in interactive graphs, check the [R graph gallery!](https://www.r-graph-gallery.com)!
<br/>