Sorry for the possibly simple question. I'm a programmer, though I rarely deal with graphics, and after tearing my hair out for hours with this problem, it's time to get some help. I'm creating a multi-panel plot in r using ggplot, but I cannot find a way to display figure labels, outside of the figure, when using ggplot.
Here is what I want my code to do:
par(mfrow = c(1, 2), pty = "s", las = 1, mgp = c(2, 0.4, 0), tcl = -0.3)
qqnorm(rnorm(100), main = "")
mtext("a", side = 3, line = 1, adj = 0, cex = 1.1)
qqnorm(rnorm(100), main = "")
mtext("b", side = 3, line = 1, adj = 0, cex = 1.1)
How would I get those "a" and "b" labels, in the location that they are in for the figure created by the above code, into this type of code:
df = data.frame(gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30))
p = ggplot(df) + geom_point(aes(x = gp, y = y))
p2 = ggplot(df) + geom_point(aes(x = y, y = gp))
grid.arrange(p, p2, ncol = 2)
Thank you in advance for your help!
You could use ggtitle
and theme
:
df = data.frame(gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30))
p = ggplot(df) + geom_point(aes(x = gp, y = y)) + ggtitle('a') + theme(plot.title=element_text(hjust=0))
p2 = ggplot(df) + geom_point(aes(x = y, y = gp)) + ggtitle('b') + theme(plot.title=element_text(hjust=0))
grid.arrange(p, p2, ncol = 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With