我如何通过ggplot2将图集中 [英] How do I leave the graph centralized by ggplot2

查看:173
本文介绍了我如何通过ggplot2将图集中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Cowplot的以下命令

I have following commands by 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).有人可以帮我吗?

But I would like to leave the graph centralized, specifically the third figure (MUFAt) of the graph. Can someone please help me?

推荐答案

使用cowplot,您不仅可以使用网格来安排图形,还可以使用draw_plot()指定在何处绘制各个图形:

Using cowplot you can arrange you graphs not only using a grid, but also specifying where to draw each individual graph using 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()

这篇关于我如何通过ggplot2将图集中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆