ggplot中换行文本的行距

geo*_*ory 4 r ggplot2

我需要更改包装的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))
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

但是theme(text=element_text(lineheight = ...))没有效果,因为它theme仅适用于绘图的非数据组件,因此我不清楚如何实现此目的。有什么建议吗?

bee*_*oot 5

只需使用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))
Run Code Online (Sandbox Code Playgroud)

(秒?geom_text

在此处输入图片说明