增加 y 轴上文本和标题之间的距离 [英] Increase distance between text and title on the y-axis
问题描述
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 =
参数t
op、r
ight、b
ottom 和 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 t
op, r
ight, b
ottom, and l
eft 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.x
、axis.text.y
和 title
.
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屋!