Skip to content

Instantly share code, notes, and snippets.

@baptiste
Created September 6, 2016 05:21
Show Gist options
  • Save baptiste/a777bec843af1d95c9518efb672a9b68 to your computer and use it in GitHub Desktop.
Save baptiste/a777bec843af1d95c9518efb672a9b68 to your computer and use it in GitHub Desktop.
library(gridExtra)
library(grid)
library(ggplot2)
xy <- polygon_regular(6)[-1,]*2
pl <- replicate(6, ggplot() + coord_polar() + theme_grey(), simplify = FALSE)
gs <- do.call(gList, lapply(1:6, function(id) grobTree(ggplotGrob(pl[[id]]), vp=letters[id])))
# gs <- do.call(gList, lapply(1:6, function(id) rectGrob(width=unit(2,"mm"), height=unit(2,"mm"), gp=gpar(fill=id), vp=letters[id])))
midpage <- unit(0.5,"npc")
xl <- lapply(xy[,1], function(x) unit(x, "cm") + midpage)
yl <- lapply(xy[,2], function(x) unit(x, "cm") + midpage)
vps <- do.call(vpList, mapply(viewport, x=xl, y=yl, name = letters[1:6],
MoreArgs = list(width=unit(2,"cm"), height=unit(2,"cm")),
SIMPLIFY = FALSE))
gl <- gTree(children = gs,
childrenvp = vps)
grid.newpage()
grid.draw(gl)
@baptiste
Copy link
Author

baptiste commented Sep 6, 2016

screen shot 2016-09-06 at 5 22 37 pm

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