如何让 ggplot2 集中图形
How do I leave the graph centralized by ggplot2
我有 cowplot 的以下命令
require(cowplot);
tiff('./solution/AGM2.tiff', height = 18,width = 25, units = 'in',res = 60)
plot_grid(a28 + theme(axis.title.y = element_text(size =40),
axis.title.x=element_text(size =40),
axis.text.x=element_text(size =35),
axis.text.y=element_text(size =40),
title=element_text(size = 30),
legend.text=element_text(size = 30)),
a33 + theme(axis.title.y = element_text(size =40),
axis.title.x=element_text(size =40),
axis.text.x=element_text(size =35),
axis.text.y=element_text(size =40),
title=element_text(size = 30),
legend.text=element_text(size = 30)),
a61 + theme(axis.title.y = element_text(size =40),
axis.title.x=element_text(size =40),
axis.text.x=element_text(size =35),
axis.text.y=element_text(size =40),
title=element_text(size = 30),
legend.text=element_text(size = 30)),
align = 'h', nrow=2, ncol = 2,hjust=0.5,vjust=0.5)
dev.off()
得到如下图
但我想让图表集中,特别是图表的第三个数字 (MUFAt)。有人可以帮我吗?
使用 cowplot
您不仅可以使用网格排列图表,还可以使用 draw_plot()
:
指定绘制每个单独图表的位置
library(ggplot2)
library(cowplot)
# theme is repeated for each plot
my_theme <- theme(axis.title.y = element_text(size = 40),
axis.title.x = element_text(size = 40),
axis.text.x = element_text(size = 35),
axis.text.y = element_text(size = 40),
title = element_text(size = 30),
legend.text = element_text(size = 30))
# Dummy plots
g1 <- ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
geom_point(size = 5, show.legend = F) +
my_theme
g2 <- ggplot(iris, aes(x = Petal.Width, y = Petal.Length, color = Species)) +
geom_point(size = 5, show.legend = F) +
my_theme
g3 <- ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
geom_smooth(show.legend = F) +
my_theme
# tiff(height = 18,width = 25, units = 'in',res = 60)
png(height = 18,width = 25, units = 'in',res = 60)
# Use x, y, height and width to customize each plot
ggdraw() +
draw_plot(g1, x = 0, y = .5, height = .5, width = .5) +
draw_plot(g2, x = .5, y = .5, height = .5, width = .5) +
draw_plot(g3, x = .25, y = 0, height = .5, width = .5)
dev.off()
或者,
gridExtra::grid.arrange(ggplot(),ggplot(),ggplot(),
layout_matrix=rbind(c(1,1,2,2),c(NA,3,3,NA)))
我有 cowplot 的以下命令
require(cowplot);
tiff('./solution/AGM2.tiff', height = 18,width = 25, units = 'in',res = 60)
plot_grid(a28 + theme(axis.title.y = element_text(size =40),
axis.title.x=element_text(size =40),
axis.text.x=element_text(size =35),
axis.text.y=element_text(size =40),
title=element_text(size = 30),
legend.text=element_text(size = 30)),
a33 + theme(axis.title.y = element_text(size =40),
axis.title.x=element_text(size =40),
axis.text.x=element_text(size =35),
axis.text.y=element_text(size =40),
title=element_text(size = 30),
legend.text=element_text(size = 30)),
a61 + theme(axis.title.y = element_text(size =40),
axis.title.x=element_text(size =40),
axis.text.x=element_text(size =35),
axis.text.y=element_text(size =40),
title=element_text(size = 30),
legend.text=element_text(size = 30)),
align = 'h', nrow=2, ncol = 2,hjust=0.5,vjust=0.5)
dev.off()
得到如下图
但我想让图表集中,特别是图表的第三个数字 (MUFAt)。有人可以帮我吗?
使用 cowplot
您不仅可以使用网格排列图表,还可以使用 draw_plot()
:
library(ggplot2)
library(cowplot)
# theme is repeated for each plot
my_theme <- theme(axis.title.y = element_text(size = 40),
axis.title.x = element_text(size = 40),
axis.text.x = element_text(size = 35),
axis.text.y = element_text(size = 40),
title = element_text(size = 30),
legend.text = element_text(size = 30))
# Dummy plots
g1 <- ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
geom_point(size = 5, show.legend = F) +
my_theme
g2 <- ggplot(iris, aes(x = Petal.Width, y = Petal.Length, color = Species)) +
geom_point(size = 5, show.legend = F) +
my_theme
g3 <- ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
geom_smooth(show.legend = F) +
my_theme
# tiff(height = 18,width = 25, units = 'in',res = 60)
png(height = 18,width = 25, units = 'in',res = 60)
# Use x, y, height and width to customize each plot
ggdraw() +
draw_plot(g1, x = 0, y = .5, height = .5, width = .5) +
draw_plot(g2, x = .5, y = .5, height = .5, width = .5) +
draw_plot(g3, x = .25, y = 0, height = .5, width = .5)
dev.off()
或者,
gridExtra::grid.arrange(ggplot(),ggplot(),ggplot(),
layout_matrix=rbind(c(1,1,2,2),c(NA,3,3,NA)))