在 ggplot2 中增加绘图区域周围的区域 [英] Increasing area around plot area in ggplot2

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

问题描述

如何增加 ggplot 2 中绘图区域周围的区域,以便为我的轴标题提供一些喘息空间.我知道 vjust 和 hjust(如下所示),但是,我似乎无法在绘图区域周围创建实际空间来移动我的轴标题.

How can I increase the area around a plot area in ggplot 2 to give my axis titles some breathing room. I am aware of vjust and hjust (as below), however, I can't seem to create actual space around the plotting area to move my axes titles onto.

p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
p

p<- p + theme(axis.title.x = element_text(family="Times",size=20,face="bold",colour = "Black",vjust=-1,hjust=0.5)) 
p

推荐答案

可以使用 theme()plot.margin= 修改图周围的边距,其中您提供大小页边距从顶部开始,然后是右侧、底部和左侧.库grid 附加到使用函数unit().

Margins around plot can be modified with theme() and plot.margin= where you provide size of margins starting with top, then right, bottom and left. Library grid is attached to use function unit().

library(grid)
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + 
  theme(axis.title.x = element_text(family="Times",size=20,
                face="bold",colour = "Black",vjust=-1,hjust=0.5))+
  theme(plot.margin=unit(c(1,1,1.5,1.2),"cm"))

这篇关于在 ggplot2 中增加绘图区域周围的区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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