gpt4 book ai didi

r - ggplot中换行文本的行距

转载 作者:行者123 更新时间:2023-12-04 09:28:31 28 4
gpt4 key购买 nike

我需要更改包裹的 geom_text 图层中的行距。

library(ggplot2)
library(stringr)
txt = c('one two three', 'four five six', 'seven eight nine')
p = ggplot(data=NULL, aes(x=1:3, y=1:3, label = str_wrap(txt, width = 3))) +
geom_text() + expand_limits(x = c(0.5, 3.5), y = c(0.5, 3.5))

enter image description here

但是 theme(text=element_text(lineheight = ...))没有效果,因为 theme仅适用于 non-data components of the plot ,所以我不清楚如何实现这一点。建议?

最佳答案

只需使用 lineheight ,例如:

ggplot(data = NULL, aes(x = 1:3, y = 1:3, 
label = str_wrap(txt, width = 3))) +
geom_text(lineheight = .5) +
expand_limits(x = c(0.5, 3.5), y = c(0.5, 3.5))

(s. ?geom_text)

enter image description here

关于r - ggplot中换行文本的行距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51133569/

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