require(cowplot)
## Loading required package: cowplot
## Loading required package: ggplot2
##
## Attaching package: 'cowplot'
##
## The following object is masked from 'package:ggplot2':
##
## ggsave
plot.mpg <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) +
geom_point(size=2.5)
plot.mpg <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) +
geom_point(size=2.5)
plot.diamonds <- ggplot(diamonds, aes(clarity, fill = cut)) + geom_bar() +
theme(axis.text.x = element_text(angle=70, vjust=0.5))
plot2by2 <- plot_grid(plot.mpg, NULL, NULL, plot.diamonds,
labels=c("A", "B", "C", "D"), ncol = 2)
t <- (0:1000)/1000
spiral <- data.frame(x = .45+.55*t*cos(t*15), y = .55-.55*t*sin(t*15), t)
ggdraw(plot.mpg) +
geom_path(data = spiral, aes(x = x, y = y, colour = t), size = 6, alpha = .4)

plot.iris <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point() + facet_grid(. ~ Species) + stat_smooth(method = "lm") +
background_grid(major = 'y', minor = "none") + # add thin horizontal lines
panel_border() # and a border around each panel
# plot.mpt and plot.diamonds were defined earlier
ggdraw() +
draw_plot(plot.iris, 0, .5, 1, .5) +
draw_plot(plot.mpg, 0, 0, .5, .5) +
draw_plot(plot.diamonds, .5, 0, .5, .5) +
draw_plot_label(c("A", "B", "C"), c(0, 0, 0.5), c(1, 0.5, 0.5), size = 15)

ggdraw() +
#geom_rect(data = boxes, aes(xmin = x, xmax = x + .15, ymin = y, ymax = y + .15),
# colour = "gray60", fill = "red", alpha=.03) +
geom_path(data = spiral, aes(x = x, y = y, colour = t), size = 6, alpha = .4) +
draw_plot(plot.diamonds, -.05, -.1, .55, .55) +
draw_plot(plot.diamonds, .65, .4, .5, .5) +
draw_plot(plot.mpg, .3, .3, .4, .4) +
draw_plot(plot.iris, 0, .7, .7, .35 ) +
draw_plot(plot.iris, .45, .0, .6, .3 )
