gpt4 book ai didi

r - 如何更改 ggplot xlab 中的行距?

转载 作者:行者123 更新时间:2023-12-02 12:13:25 25 4
gpt4 key购买 nike

我的X轴标签太长,所以我使用了xlab(表达式(atop(paste("Hello world"^"TM ", ":Hi"),paste("hello Again"^"TM",": Hi")))) 将其分成两行。行距太大,我应用了axis.title.x=element_text(lineheight=0.2)方法来改变行距,但没有改变任何东西。该方法改编自here 。我的问题是如何更改 xlab 的行间距。预先感谢您!

最佳答案

要使所有内容完美居中(\n 不会这样做),请使每段文本保持相同的大小,无论行数多少,同时能够调整行间空间,使用这个代替:

xlab(expression(atop(textstyle("whateverline1"),atop(textstyle("whateverline2"),atop(scriptscriptstyle(""),textstyle("whateverline3"))))))

然后使用labeller=label_parsed
这也适用于 facet_gridtitleylab

请注意 atoptextstyle 来定位文本,同时保持其大小相同,并使用 scriptscriptstyle("") 来控制间距行与行之间。您还可以根据需要使用 scriptstylescriptscriptstyle 使用不同的相对文本大小,当然还可以使用 axis.title.x=element_text(size=whatevernumber) 在主题部分

关于r - 如何更改 ggplot xlab 中的行距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28810453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com