library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.2     ✓ dplyr   1.0.7
## ✓ tidyr   1.0.2     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## Warning: package 'ggplot2' was built under R version 3.6.2
## Warning: package 'tibble' was built under R version 3.6.2
## Warning: package 'purrr' was built under R version 3.6.2
## Warning: package 'dplyr' was built under R version 3.6.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
datasets::anscombe %>%
  pivot_longer(cols = 1:8) %>%
  mutate(group = str_extract(name, "\\d")) %>%
  mutate(var = str_extract(name, "\\w")) %>% 
  select(-name) %>% 
  pivot_wider(names_from = var, 
              values_from = value) %>% 
  unnest() ->
tidy_anscombe
## Warning: Values in `value` are not uniquely identified; output will contain list-cols.
## * Use `values_fn = list(value = list)` to suppress this warning.
## * Use `values_fn = list(value = length)` to identify where the duplicates arise
## * Use `values_fn = list(value = summary_fun)` to summarise duplicates
## Warning: `cols` is now required.
## Please use `cols = c(x, y)`
tidy_anscombe %>% 
  ggplot() + 
  aes(x = x, y = y) + 
  geom_point(size= 5, color = "darkmagenta") + 
  # aes(color = group) + 
  facet_wrap(facets = vars(paste("dataset", group))) + 
  # mean of x
  ggxmean::geom_x_mean(linetype = "dashed", lwd = 1, color = "darkmagenta") + 
  ggxmean::geom_y_mean(linetype = "dashed",lwd = 1, color = "darkmagenta") + 
  # mean of y
  ggxmean:::geom_x1sd(linetype = "dotted", lwd = 1, color = "darkmagenta") + 
  ggxmean:::geom_y1sd(linetype = "dotted",lwd = 1, color = "darkmagenta") + 
  # linear model
  # ggxmean::geom_lm(lwd = 1) + 
  # ggxmean::geom_lm_formula() + 
  # Pearson correlation
  # ggxmean:::geom_corrlabel() + 
  theme_void() +
  theme(legend.position = "none") +
  NULL

ggsave("ggxmean_plots.png",
       plot = last_plot())
## Saving 7 x 5 in image
knitr::include_graphics("ggxmean_plots.png")

library(ggstamp)

ggcanvas() + 
  stamp_png(png = "ggxmean_plots.png", reduce = 100) + 
  stamp_wash(fill = "linen", alpha = .6) + 
  stamp_text( y = -0, x = 0, size = 5,
             label = "ggxmean",
             color = "lightblue4") + 
    # coord_equal(xlim = c(-3,3), ylim = c(-2.3, 2.3)) + 
  stamp_text(angle = 30, label = "github.com/...",
             x = 0, y = -1.45, size = 1.8, 
             color = "brown") + 
    stamp_polygon(radius = .7,
                alpha = 0, size = 7,
                color = alpha("rosybrown4", .9)) +
    stamp_polygon_inverse(radius = .7, radius_outer = Inf, 
                        fill = "white", color = "red"
                         ) +
  theme_void_fill(fill = "white") +
  NULL
## Warning: Ignoring unknown aesthetics: x, y