增加 y 轴上文本和标题之间的距离 [英] Increase distance between text and title on the y-axis

查看:25
本文介绍了增加 y 轴上文本和标题之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

y 轴标题与轴文本太近.

The y-axis title appears too close to the axis text.

ggplot(mpg, aes(cty, hwy)) + geom_point()

我曾尝试使用 theme() 更改许多参数的值,但似乎没有任何帮助.

I have tried changing the value of many parameters with theme() but none seems to help.

推荐答案

ggplot2 2.0.0 你可以使用 element_text() 的 margin = 参数 改变轴标题和数字之间的距离.在 top、right、bottom 和 l<上设置 margin 的值/code>元素的左端.

From ggplot2 2.0.0 you can use the margin = argument of element_text() to change the distance between the axis title and the numbers. Set the values of the margin on top, right, bottom, and left side of the element.

ggplot(mpg, aes(cty, hwy)) + geom_point()+
  theme(axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)))


margin 也可以用于其他 element_text 元素(参见 ?theme),例如 axis.text.xaxis.text.ytitle.


margin can also be used for other element_text elements (see ?theme), such as axis.text.x, axis.text.y and title.

添加

为了在轴具有不同位置时设置轴标题的边距(例如,使用 scale_x_...(position = "top"),您需要一个不同的主题设置 - 例如 axis.title.x.top.参见 https://github.com/tidyverse/ggplot2/issues/4343.

in order to set the margin for axis titles when the axis has a different position (e.g., with scale_x_...(position = "top"), you'll need a different theme setting - e.g. axis.title.x.top. See https://github.com/tidyverse/ggplot2/issues/4343.

这篇关于增加 y 轴上文本和标题之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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