R - ggplot 标题:无法在左侧添加边距.这是一个错误吗?



我一直试图将ggplot的标题放在面板中。我有这样的东西:

ggplot(mtcars, aes(x = hp, y = mpg)) +
geom_point() +
labs(title = "This is my titlensecond part") +
theme(
plot.title = element_text(margin = margin(b = -40, l = 40))
)

我不确定为什么我不能在我的标题左侧给出一些边距。我尝试了许多值,排列,但似乎不起作用。如果需要,我可以使用hjust = 0.5将其居中,但不能仅在左侧提供边距。

我认为这可能是一个错误,为什么这不起作用对我来说没有意义。以下是使用ggtext包的解决方法。可能需要稍微摆弄一下确切的边距值。

library(ggtext)
ggplot(mtcars, aes(x = hp, y = mpg)) +
geom_point() +
labs(title = "This is my titlensecond part") +
theme(
plot.title = element_textbox(margin = margin(t = 5.5, b= -40, l = 40))
)

相关内容

最新更新