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

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

问题描述

如何增加ggplot 2中的绘图区域以使我的轴标题具有一定的呼吸空间。我知道vjust和hjust(如下),但是,我似乎无法在绘图区域周围创建实际空间来移动我的轴标题。



<$ p $ (x,y,y,mpg))+ geom_point()
p

p < - p +主题((mtcars,aes axis.title.x = element_text(family =Times,size = 20,face =bold,color =Black,vjust = -1,hjust = 0.5))
p

theme()来修改绘图周围的空白处。 >和 plot.margin = 您可以提供从顶部开始,然后是右侧,底部和左侧的边距尺寸。使用函数 unit()附加库 grid

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


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

解决方案

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天全站免登陆