[R] how to word-wrap text in labels in plots?
    Jim Lemon 
    jim at bitwrit.com.au
       
    Wed Apr 29 13:57:45 CEST 2009
    
    
  
Hans Ekbrand wrote:
> c <- structure(c(2L, 2L, 1L, 3L, 4L, 2L, 3L, 2L, 3L, 2L, 5L), .Label = c("foo", 
> + "bar", "a really really long variable label mostly here to show the need of word-wrapping text in labels", 
> + "a not so important value", "baz"), class = "factor")
> plot(c)
>
> Is there a way to get the long variable labels to automatically wrap so that all labels can be shown?
>
> Alternatively, is there a way to get the labels truncated, possibly with ".." appended?
>   
As the first question has already been answered, you can truncate 
strings like this example from the htmlize function in the prettyR package:
 navitem<-ifelse(nchar(Rcommand)>20,
  paste(paste(unlist(strsplit(Rcommand,""))[1:18],sep="",collapse=""),
   "...",sep="",collapse=""),Rcommand)
Jim
    
    
More information about the R-help
mailing list