Skip to content

Instantly share code, notes, and snippets.

@baptiste
Last active September 23, 2016 21:27
Show Gist options
  • Select an option

  • Save baptiste/7cb876a3e672216d2d0e19b68dc5a51d to your computer and use it in GitHub Desktop.

Select an option

Save baptiste/7cb876a3e672216d2d0e19b68dc5a51d to your computer and use it in GitHub Desktop.
poll
library(ggplot2)
library(xkcd)
library(grid)
library(gtable)
N <- 573
d <- data.frame(y = factor(sample(c("top", "centre"), N, TRUE), levels=c("bottom","centre","top")))
p1 <- ggplot(d, aes(x = y, fill = y)) + geom_bar() + coord_flip() +
scale_x_discrete("", drop=FALSE) +
labs(x = "", y = "", fill = "centre") +
guides(fill = guide_legend(reverse = TRUE))+ theme_xkcd()
p2 <- p1 + theme(legend.justification = "top") +
labs(fill = "top", colour="top")
g1 <- ggplotGrob(p1)
g2 <- ggplotGrob(p2)
pos <- g2$layout[15,]
g2 <- gtable_add_grob(g2, g1$grobs[[15]], pos$t, pos$l, pos$b, pos$r)
grid.newpage()
grid.draw(g2)
@baptiste
Copy link
Author

baptiste commented Sep 23, 2016

screen shot 2016-09-24 at 9 26 14 am

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