--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
#create simple dataframe for plottingxy <- data.frame(x = rep(1:10, times=3), y = rep(10:1, times=3), type = rep(c("this is a really long factor level name that will screw things up hopefully, but I'm not sure if I can wrap this text with wrapper", "other title"), each=5), type2 = rep(LETTERS[3:5], each=10))#create base plotplot <- ggplot(data = xy)+geom_point(aes(x = x, y = y))+
facet_grid(type ~ type2, labeller= label_wrapper, widht = 20)
I don't think you can pull this off in general, though you are on the
right track if you could. the label_* functions take the arguments
(variable, value) [both vectors], and return a list or vector (of the
same length) of strings. The problem is, there is no ... that could be
used to pass something through. The best approach I could think would
be using the label_wrapper that Luciano gave, with an additional wrapper
around that which fixes the width to pass to the labeller argument of
the facet:
label_wrapper30 <- function(variable, value) {
label_wrapper(variable, value, 30)
}
Then, following Brandon's code:
plot <- ggplot(data = xy)+
geom_point(aes(x = x, y = y))+
facet_grid(type ~ type2, labeller= label_wrapper30)
> On Thu, Apr 7, 2011 at 13:58, Luciano Selzer<luciano.selzer-Re5...@public.gmane.org>wrote:
>
>> Hi all, looking at label_parsed I modified wrapper into label_wrapper and
>> now works partially. The thing is, facetter passes and wants a list. But I
>> don't know how to pass the width to strwrap. Any ideas?
>>
>> label_wrapper<- function(variable, value, ...) {
>> llply(as.character(value), function (x) paste(strwrap(x, ...), collapse
>> = "\n"))
>> }
>>
>>
>> Luciano
>>
>>
>> 2011/4/7 Brandon Hurr<brandon.hurr-Re5J...@public.gmane.org>
>>>>> On Thu, Apr 7, 2011 at 11:37, Brandon Hurr<brandon.h...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>>>> wrote:
>>>>>> My bad, that was totally unhelpful.
>>>>>
>>>>>> You said strip text and I thought axis text. With the labs() function
>>>> that
>>>>>> won't work.
>>>>>
>>>>>> B
>>>>>
>>>>>> On Thu, Apr 7, 2011 at 11:33, Brandon Hurr<brandon.h...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>>>> wrote:
>>>>>
>>>>>>> You could try...
>>>>>>> plot+labs(x=wrapper(my_title))
>>>>>
>>>>>>> I tried it and it didn't quite seem to be wrapping properly. You may
>>>> need
>>>>>>> to adjust the length of the string before it's split.
>>>>>
>>>>>>> Brandon
>>>>>
>>>>>>> On Thu, Apr 7, 2011 at 11:03, alienk8<alienz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>>>>>
>>>>>>>> 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"
>>>>
>>>> --
>>>> You received this message because you are subscribed to the ggplot2
>>>> mailing list.
>>>> Please provide a reproducible example: http://gist.github.com/270442
>>>>
>>>> To post: email ggplot2-/JYPxA39Uh5...@public.gmane.org
>>>> To unsubscribe: email ggplot2+unsubscribe-/JYPxA39Uh5...@public.gmane.org
>>>> More options: http://groups.google.com/group/ggplot2
>>>>
>>>
>>> --
>>> You received this message because you are subscribed to the ggplot2
>>> mailing list.
>>> Please provide a reproducible example: http://gist.github.com/270442
>>>
>>> To post: email ggplot2-/JYPxA39Uh5...@public.gmane.org
>>> To unsubscribe: email ggplot2+unsubscribe-/JYPxA39Uh5...@public.gmane.org
>>> More options: http://groups.google.com/group/ggplot2
>>>
>>
>>
>
--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University
http://stackoverflow.com/questions/5574157/r-ggplot2-can-i-make-the-facet-strip-text-wrap-around
baptiste
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>