I need to change the line spacing in wrapped geom_text layer.
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))
But theme(text=element_text(lineheight = ...))
has no effect because theme
only works for non-data components of the plot, so I'm not clear how to achieve this. Suggestions?
Just use lineheight
, e.g.:
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With