ggplot2绘制区域边际? [英] ggplot2 plot area margins?

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

问题描述

是否有一种简单的方法可以增加小区标题和它下面的绘图区域(包含数据的框)之间的空间。同样,我希望在轴标题和轴标签之间留出一些空间。换句话说,有没有办法将标题稍微向上移动一些, y轴标题有点左,x轴标题有点下移?

解决方案

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

  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 (plot.title = element_text(size = 15,vjust = 3))+
theme(plot.margin = unit(c(1,1,1, 1),cm))

会给你这样的东西:





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


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"?

解决方案

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"))

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.

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

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