简体   繁体   English

ggplot2绘图区域边距?

[英]ggplot2 plot area margins?

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. 同样,我更喜欢在轴标题和轴标签之间留一些空格。

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"? 换句话说,有没有办法“将标题向上移动,y轴标题稍微向左移动,x轴标题稍微向下移动”?

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() . 您可以使用theme() plot.margin调整绘图边距,然后使用element_text()vjust参数移动轴标签和标题。 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"))

will give you something like this : 会给你这样的东西:

在此输入图像描述

If you want more informations about the different theme() parameters and their arguments, you can just enter ?theme at the R prompt. 如果您想了解有关不同theme()参数及其参数的更多信息,可以在R提示符下输入?theme

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM