seq_x <- seq (from = 0 ,
to = 2 * pi,
by = pi / 100 )
n_lines <- 11
data_left_and_right <- tibble (x = rep (seq_x, 9 ),
line = rep (seq (- 1 , 7 ), each = length (seq_x))) %>%
mutate (y = line + sin (x))
data_arrows_left_and_right <- data_left_and_right %>%
filter (x %in% c (seq_x[c (100 , 102 )]),
between (line, 1 , 6 )) %>%
group_by (line) %>%
summarise (xmin = min (x),
xmax = max (x),
ymax = max (y),
ymin = min (y))
gg_left_to_right <- data_left_and_right %>%
ggplot (aes (x = x, y = y, group = line)) +
geom_segment (data = data_arrows_left_and_right,
aes (x = xmin, y = ymax, xend = xmax, yend = ymin, group = line),
arrow = arrow (type= "closed" , ends = "last" ), linewidth = 5 , show.legend = FALSE ) +
geom_path (linewidth = 5 ,
show.legend = FALSE ,
aes (colour = ifelse (between (line, 1 , 6 ), "main" , "background" ))) +
scale_x_continuous (expand = expansion (0 , - 0.1 )) +
scale_y_continuous (expand = expansion (0 , 0 )) +
scale_colour_manual (values = c ("main" = "black" ,
"background" = "grey80" )) +
coord_fixed (ratio = 1 / 2 , ylim = c (0 , 7 ), xlim = c (0 , 2 * pi)) +
theme_void () +
theme (
panel.background = element_rect (fill = "#9A7D66" , colour = "transparent" ),
panel.border = element_blank ()
)
gg_right_to_left <- data_left_and_right %>%
ggplot (aes (x = x, y = y, group = line)) +
geom_segment (data = data_arrows_left_and_right,
aes (x = xmin, y = ymax, xend = xmax, yend = ymin, group = line),
arrow = arrow (type= "closed" , ends = "first" ), linewidth = 5 , show.legend = FALSE ) +
geom_path (linewidth = 5 ,
show.legend = FALSE ,
aes (colour = ifelse (between (line, 1 , 6 ), "main" , "background" ))) +
scale_x_continuous (expand = expansion (0 , - 0.1 )) +
scale_y_continuous (expand = expansion (0 , 0 )) +
scale_colour_manual (values = c ("main" = "black" ,
"background" = "grey80" )) +
coord_fixed (ratio = 1 / 2 , ylim = c (0 , 7 ), xlim = c (0 , 2 * pi)) +
theme_void () +
theme (
panel.background = element_rect (fill = "#9A7D66" , colour = "transparent" ),
panel.border = element_blank ()
)
ggptch_left_and_right <- gg_left_to_right + theme (plot.margin = margin (r = 20 )) | gg_right_to_left
ggptch_left_and_right %>%
ggsave (quarto_here ("ggptch_left_and_right.png" ),
.,
width = 5 * 2 + 0.5 ,
height = 2.5 * 2 + 1.5 )