I would like to change the position of each label to the bottom and centered part of each figure, is it possible?
library(ggplot2)
library(cowplot)
df <- data.frame(
x = 1:10, y1 = 1:10, y2 = (1:10)^2, y3 = (1:10)^3, y4 = (1:10)^4
š§š·
p1 <- ggplot(df, aes(x, y1)) + geom_point()
p2 <- ggplot(df, aes(x, y2)) + geom_point()
p3 <- ggplot(df, aes(x, y3)) + geom_point()
p4 <- ggplot(df, aes(x, y4)) + geom_point()
# Create a simple grid
p <- plot_grid(p1, p2, p3, p4, align = 'hv')
# Default font size and position
p + draw_figure_label(label = "Figure 1")
I would like to put a label for each figure:
(a) Figure 1 (b) Figure 2 (c) Figure 3 (d) Figure 4
However, I would like the labels to be at the bottom for each figure. It's possible ?
The problem is that draw_figure_label
is for drawing a single label on the whole grid, not for drawing labels on each plot. You would be far better adding a caption to each plot to get the same effect:
p <- Map(function(a, b) {
a +
labs(caption = b) +
theme(plot.caption.position = 'panel',
plot.caption = element_text(hjust = 0.5, size = 12, face = 2,
margin = margin(10, 0, 30, 0)))
},
a = list(p1, p2, p3, p4),
b = list('(a) Figure 1', '(b) Figure 2', '(c) Figure 3', '(d) Figure 4'))
Now recreate your grid:
plot_grid(p[[1]], p[[2]], p[[3]], p[[4]], align = 'hv')