I have a figure that contains 4 subfigures and want to add only one figure label on the left top corner, say (A). How can I add that line in my code below?
data("iris")
iris1 <- iris2 <- iris3 <- iris
fig <- list()
fig[[1]] <- ggplot(data=iris,mapping=aes(x=Petal.Length,y=Petal.Width,color=Species))+
geom_point()+
geom_smooth(method="lm") +
labs(title = paste0("the title is ", expression(m[0])))
fig[[2]] <- ggplot(data=iris1,mapping=aes(x=Petal.Length,y=Petal.Width,color=Species))+
geom_point()+
geom_smooth(method="lm") +
labs(title = paste0("the title is ", expression(m[1])))
fig[[3]] <- ggplot(data=iris2,mapping=aes(x=Petal.Length,y=Petal.Width,color=Species))+
geom_point()+
geom_smooth(method="lm") +
labs(title = paste0("the title is ", expression(m[2])))
fig[[4]] <- ggplot(data=iris3,mapping=aes(x=Petal.Length,y=Petal.Width,color=Species))+
geom_point()+
geom_smooth(method="lm") +
labs(title = paste0("the title is ", expression(m[3])))
fig_all <- ggpubr::ggarrange(plotlist = fig, ncol = 2, nrow = 2, common.legend = TRUE, legend = "top")
fig_all
The generated figure is as follows, but there is no figure label. I don't want to have label for each subfigures, but instead just one label to indicate for all, on the top left corner.
You can use ggpubr::annotate_figure
library("ggplot2")
library("ggpubr")
data("iris")
fig <- list()
fig[[1]] <- ggplot(data=iris,mapping=aes(x=Petal.Length,y=Petal.Width,color=Species))+
geom_point()+
geom_smooth(method="lm")
fig[[2]] <- ggplot(data=iris,mapping=aes(x=Petal.Length,y=Petal.Width,color=Species))+
geom_point()+
geom_smooth(method="lm")
fig[[3]] <- ggplot(data=iris,mapping=aes(x=Petal.Length,y=Petal.Width,color=Species))+
geom_point()+
geom_smooth(method="lm")
fig[[4]] <- ggplot(data=iris,mapping=aes(x=Petal.Length,y=Petal.Width,color=Species))+
geom_point()+
geom_smooth(method="lm")
fig_all <- ggpubr::ggarrange(plotlist = fig, ncol = 2, nrow = 2, common.legend = TRUE, legend = "top")
ggpubr::annotate_figure(fig_all,
fig.lab = 'Main Title',
fig.lab.pos = 'top.left',
fig.lab.size = 16,
fig.lab.face = 'bold')