Reputation: 23660
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?
Upvotes: 28
Views: 8844
Reputation: 10133
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
)
Upvotes: 49