ggplot2绘制区域边际? [英] ggplot2 plot area margins?
问题描述
是否有一种简单的方法可以增加小区标题和它下面的绘图区域(包含数据的框)之间的空间。同样,我希望在轴标题和轴标签之间留出一些空间。换句话说,有没有办法将标题稍微向上移动一些, 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屋!