This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| d <- data.frame(x=1:20, f = gl(2, 10)) | |
| p <- ggplot(d, aes(x,x, colour=x)) + facet_grid(.~f) + | |
| ggtitle("facetted plot") | |
| library(egg) | |
| expose_layout(p) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| # dput(ls(pattern = "theme",package:ggplot2)) | |
| defaults <- c("theme_bw", "theme_classic", "theme_dark", | |
| "theme_grey", "theme_light", "theme_linedraw", | |
| "theme_minimal", "theme_void") | |
| library(ggthemes) | |
| # dput(ls(pattern = "theme",package:ggthemes)) | |
| addons <- c("theme_base", "theme_calc", "theme_economist", | |
| "theme_economist_white", "theme_excel", "theme_few", "theme_fivethirtyeight", | |
| "theme_foundation", "theme_gdocs", "theme_hc", "theme_igray", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| p <- qplot(1:10,1:10, label="aa", geom="text") + | |
| theme(plot.title = element_text(colour = "red")) + | |
| ggtitle("Red is the colour") | |
| p | |
| # gb <- ggplot_build(p) | |
| # ggplot_gtable(gb) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(scales) | |
| library(dplyr) | |
| # http://www.stuff.co.nz/national/86458731/Cheviot-earthquake-Tracing-the-source-of-the-7-5-magnitude-quake-and-its-aftermath?utm_source=dlvr.it&utm_medium=twitter | |
| eqs <- data.frame( | |
| energy = c(48.99, 13.34, 2.67, 6.25, 4.93, 2.71, 4.73, 16.38), | |
| period = c("Nov 14 2016", "Earlier 2016", paste("All", 2015:2010)), | |
| stringsAsFactors = FALSE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(gridExtra) | |
| library(grid) | |
| grid.arrange(grobs = lapply(1:5, textGrob)) | |
| grid.arrange(grobs = lapply(1:5, textGrob), as.table=FALSE) | |
| grid.arrange(grobs = lapply(1:5, textGrob), layout_matrix = matrix(c(1:5,NA), ncol=2)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(grid) | |
| my_axis <- function(low="low", high="high", axis=c("x", "y"), ...){ | |
| axis <- match.arg(axis) | |
| if(axis == "x"){ | |
| g1 <- textGrob(low, x=unit(0,"npc"), hjust=0) | |
| g3 <- textGrob(high, x=unit(1,"npc"), hjust=1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| p <- ggplot(data = diamonds, mapping = aes(x = clarity)) + geom_bar(aes(fill = cut)) + | |
| theme_void() + | |
| theme(legend.position="none", | |
| panel.background = element_rect(fill="grey80"), | |
| plot.background = element_rect(fill="red")) | |
| g <- ggplotGrob(p) | |
| grid::grid.newpage() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(grid) | |
| p <- qplot(1,1) + labs(y="y title") + | |
| theme(axis.title.y = element_text(angle = 0)) | |
| g <- ggplotGrob(p) | |
| id <- which(g$layout$name == "ylab-l") |