Last active
July 25, 2017 17:14
-
-
Save jackbrookes/271e89f975490444731279dd72d0125d to your computer and use it in GitHub Desktop.
Example of how to combine plots with images side-by-side in cowplot for publication ready figures.
This file contains 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(png) | |
library(grid) | |
library(tidyverse) | |
# generate random data | |
my.data <- data.frame(x = c(1:10), y = rnorm(10)) | |
# plot random data | |
g <- ggplot(my.data, aes(x = x, y = y)) + | |
geom_point() | |
# define plot png function | |
plot_png <- function(fname){ | |
img <- readPNG(fname) %>% | |
rasterGrob(interpolate=FALSE) | |
ggplot() + | |
annotation_custom(img, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) | |
} | |
# create our ggplot-compatible png | |
img <- plot_png("task.png") | |
# plot images together in grid | |
plot_grid(g, img, labels = letters) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment