我想将三个图形的组合保存为 pdf - 一个 ggplot 和两个 ggplotGrob。使用我正在尝试的代码,这些数字相互重叠。
library(ggplot2)
library(condformat)
library(ggpubr)
data(iris)
graph1 <- ggplot(data=iris, aes(Sepal.Length, y=Sepal.Width, color=Species)) +
geom_point(aes(shape=Species), size=1.5) + geom_smooth(method="lm") +
xlab("Sepal Length") + ylab("Sepal Width")
table1 <- condformat(iris[10:20, 1:4]) %>%
rule_text_color(Sepal.Length, ifelse(Sepal.Length >= 4.6, "red", "")) %>%
condformat2grob()
Plots <- ggarrange(graph1,
ggarrange(table1, tableGrob(iris[10:20, 3:4]), ncol = 2, labels = c("B", "C")),
nrow = 2,
labels = "A" ,
heights=c(3,2,1))
annotate_figure(Plots,
top = text_grob("Graphs", color = "black", face = "bold", size = 20),
bottom = text_grob("Figure 1. write legend here.",
hjust = 1, x = 1, size = 9))
ggsave(filename="Plots.pdf", Plots, width=11, height=8.5)
dev.off()