ggplot2 绘图区边距? [英] ggplot2 plot area margins?

查看:50
本文介绍了ggplot2 绘图区边距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以增加绘图标题与其下方绘图区域(带有数据的框)之间的空间.同样,我希望在轴标题和轴标签之间留出一些空间.

Is there an easy way to increase the space between the plot title and the plot area below it (the box with the data). Similarly, I'd prefer to have some space between the axis title and axis labels.

换句话说,有没有办法将标题向上移动一点,y 轴标题向左移动一点,x 轴标题向下移动一点"?

In other words, is there a way to "move the title a bit up, the y axis title a bit left, and the x axis title a bit down"?

推荐答案

您可以使用 theme() 中的 plot.margin 调整绘图边距,然后移动轴标签和标题与 element_text()vjust 参数.例如:

You can adjust the plot margins with plot.margin in theme() and then move your axis labels and title with the vjust argument of element_text(). For example :

library(ggplot2)
library(grid)
qplot(rnorm(100)) +
    ggtitle("Title") +
    theme(axis.title.x=element_text(vjust=-2)) +
    theme(axis.title.y=element_text(angle=90, vjust=-0.5)) +
    theme(plot.title=element_text(size=15, vjust=3)) +
    theme(plot.margin = unit(c(1,1,1,1), "cm"))

会给你这样的东西:

如果您想了解有关不同 theme() 参数及其参数的更多信息,只需在 R 提示符下输入 ?theme 即可.

If you want more informations about the different theme() parameters and their arguments, you can just enter ?theme at the R prompt.

这篇关于ggplot2 绘图区边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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