Skip to content

Instantly share code, notes, and snippets.

@baptiste
Created April 1, 2020 20:59
Show Gist options
  • Save baptiste/cee64b5bf753dca35a5d5c9aa927e234 to your computer and use it in GitHub Desktop.
Save baptiste/cee64b5bf753dca35a5d5c9aa927e234 to your computer and use it in GitHub Desktop.
library(ggplot2)
library(egg)
library(extrafont)
library(xkcd)
library(grid)
d <- data.frame(x=rep(-1:1,3),y=0,facet=rep(1:3,each=3))
p0 <- ggplot(d, aes(x,y)) +
facet_wrap(~facet, labeller = label_both) +
geom_blank() +
xkcdaxis(c(-1,1),c(-1,1)) +
theme(axis.text = element_blank(),
axis.ticks = element_blank(),
axis.ticks.length = unit(0,'mm'),
axis.title = element_text())
p1 <- p0 %+% subset(d, facet < 2)
p2 <- p0 %+% subset(d, facet < 3)
p3 <- p0 %+% subset(d, facet < 4)
d2 <- data.frame(x=0,y=0,facet=1:3)
d2$subplots <- I(lapply(list(p1,p2,p3), ggplotGrob))
p0 + geom_custom(data=d2, aes(data=subplots), grob_fun = identity)+
xkcdaxis(c(-1,1),c(-1,1)) +
theme(strip.text = element_text(colour = "black")) +
theme(axis.text = element_blank(),
axis.ticks = element_blank()) +
labs(title='Facets',subtitle = 'facetted by number of facets')
@baptiste
Copy link
Author

baptiste commented Apr 1, 2020

Screen Shot 2020-04-02 at 9 50 32 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment