Change spacing between lines in a label

1,182 views
Skip to first unread message

Frans Marcelissen

unread,
Oct 5, 2016, 5:09:34 AM10/5/16
to ggplot2
I often have long (x) labels, for instance because I use the question of a survey as a label. These labels can be too long to display on one line. So I split the lines by inserting \n between them.
For instance 

library(ggplot2)
df2<-  data.frame(v1=factor(c('Do you intend\nto buy this product\nif the price is\nbelow 16 euro\'s, even if \n there are\n better products?', 'Another label1')),v2=runif(2))
ggplot(df2)+aes(x=v1, y=v2)+geom_bar(stat='identity')+coord_flip()

(This is just an minimal example, here the spacing is no problem, but when the number of bars is larger, the spacing becomes problematic).

Now I would like the increase of decrease the spacing between these lines of one label. Does anyone know whether there is a way to do this?
Thanks
Frans

ep...@webkartet.no

unread,
Oct 5, 2016, 7:43:40 AM10/5/16
to ggplot2
You can increase or decrease the spacing by
+   theme(axis.text.y = element_text(lineheight=.5))

Also: Check out the scales-package for automatic wrapping of labels
scales::wrap_format()


I expect changing the spacing will be done by
+   theme(axis.text.x = element_text(lineheight=.5))
Reply all
Reply to author
Forward
0 new messages