[R] Left align plot_grid titles?
Mike Smith
mike at hsm.org.uk
Tue May 10 19:40:47 CEST 2016
Is there any way to left align titles automatically in plot_grid?? Currently using this code which centre aligns the whole plot title
thanks!
library(ggplot2)
library(cowplot)
data <- read.csv("http://www.lecturematerials.co.uk/data/times_tables.csv",header=T)
gg1<-ggplot(data,aes(x=multiplier,y=factor)) +
geom_point(aes(colour=incorrect), size=8, shape=15) +
scale_colour_distiller(palette = "Spectral", direction=-1, guide="colourbar", name="Incorrect (%)") +
scale_x_continuous(name="Multiplier", limits=c(1, 12), breaks=seq(2,12,by=2)) +
scale_y_continuous(name="Factor", limits=c(1, 12), breaks=seq(2,12,by=2)) +
geom_abline(intercept = 0, slope = 1, size=1) +
coord_fixed()
gg2<-ggplot(data,aes(x=multiplier,y=factor)) +
geom_point(aes(colour=incorrect), size=8, shape=15) +
scale_colour_distiller(palette = "Spectral", direction=-1, guide="colourbar", name="Incorrect (%)") +
scale_x_continuous(name="Multiplier", limits=c(1, 12), breaks=seq(2,12,by=2)) +
scale_y_continuous(name="Factor", limits=c(1, 12), breaks=seq(2,12,by=2)) +
geom_abline(intercept = 0, slope = 1, size=1) +
coord_fixed()
p<-plot_grid(gg1,gg2,labels=c("A", "B"), nrow = 2)
title <- ggdraw() + draw_label("A Title", fontface='bold')
plot_grid(title, p, ncol=1, rel_heights=c(0.1, 1), align=c("h")) # rel_heights values control title margins
---
Mike Smith
More information about the R-help
mailing list