Skip to content

Instantly share code, notes, and snippets.

@atusy
Last active October 30, 2018 03:59
Show Gist options
  • Save atusy/f3aa8161b9a4093e04745529679418fa to your computer and use it in GitHub Desktop.
Save atusy/f3aa8161b9a4093e04745529679418fa to your computer and use it in GitHub Desktop.
---
title: "Enjoy patchwork"
output: html_notebook
---
```{r setup, include = FALSE}
library(dplyr)
library(ggplot2)
library(patchwork)
```
```{r, fig.dim = c(0.5 + sqrt(1.25), 1) * 3, message = FALSE, warning = FALSE}
d <- data.frame(theta = seq(0, 360, 0.01) / 2 / pi) %>%
mutate(x = cos(theta), y = sin(theta))
layers <- list( # layers to draw circle
geom_path(),
coord_cartesian(xlim = c(0, 1), ylim = c(0, 1), expand = FALSE),
theme_gray(),
theme(
axis.ticks = element_blank(),
axis.title = element_blank(),
axis.text = element_blank(),
plot.margin = unit(c(0,0,0,0),'mm')
)
)
LT <- ggplot(d, aes(x + 1, y)) + layers # left to top pie
TR <- ggplot(d, aes(x, y)) + layers # top to right pie
RB <- ggplot(d, aes(x, y + 1)) + layers # right to bottom pie
BL <- ggplot(d, aes(x + 1, y + 1)) + layers # bottom to left pie
gold <- 0.5 + sqrt(1.25)
R <- function(x = TR) { # next is on the right
wrap_plots(LT, x, widths = c(gold, 1), nrow = 1)
}
B <- function(x = RB) { # next is on the bottom
wrap_plots(TR, x, heights = c(gold, 1), ncol = 1)
}
L <- function(x = BL) { # next is on the left
wrap_plots(x, RB, widths = c(1, gold), nrow = 1)
}
T <- function(x = LT) { # next is on the top
wrap_plots(x, BL, heights = c(1, gold), ncol = 1)
}
R(B(L(T(R(B())))))
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment