Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: ggplot2, can I make the facet/strip text wrap around?

Tags:

r

ggplot2

I found this very useful code for wrapping text here:

 wrapper <- function(x, ...) paste(strwrap(x, ...), collapse = "\n")`

 my_title <- "This is a really long title of a plot that I want to nicely wrap and fit onto the plot without having to manually add the backslash n, but at the moment it does not"

 r + geom_smooth() + opts(title = wrapper(my_title, width = 20))

I would like to use it to wrap the text in a facet/strip but don't know how.

 p + geom_bar(stat="identity")+facet_wrap(~variable1) + 
    opts(strip.text.x=theme_text(size=12, face="bold")

Is it passed to the strip.text.x options?

like image 550
alienk8 Avatar asked Apr 06 '11 23:04

alienk8


1 Answers

Since this question was posted, the new label_wrap_gen() function with ggplot2 (>= 1.0.0, I think) handles this nicely:

facet_wrap(~variable1, labeller = label_wrap_gen())
like image 198
CephBirk Avatar answered Sep 19 '22 07:09

CephBirk