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? -- Hans Ekbrand (http://sociologi.cjb.net) <hans at sociologi.cjb.net> Q. What is that strange attachment in this mail? A. My digital signature, see www.gnupg.org for info on how you could use it to ensure that this mail is from me and has not been altered on the way to you. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: Digital signature URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090429/80698574/attachment-0002.bin>
Hi Hans, strwrap is your friend. "\n" inserts a cr in a line of text. wordwrap<-function(x,len) paste(strwrap(x,width=len),collapse="\n") par(mar=c(11,3,2,1)) tmp<-plot(c,axes=F) axis(2) axis(1,at=tmp,labels=sapply(levels(c),wordwrap,len=15),padj=1) box() For unique abbreviations see ?abbreviate hth. Hans Ekbrand schrieb:> 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? > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Eik Vettorazzi Institut f?r Medizinische Biometrie und Epidemiologie Universit?tsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790
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
Thanks to Jim and Eik! I really appreciate your help, and I think can use your suggestions and perhaps write a wrapper for plot that integrates them. -- Hans Ekbrand (http://sociologi.cjb.net) <hans at sociologi.cjb.net> Q. What is that strange attachment in this mail? A. My digital signature, see www.gnupg.org for info on how you could use it to ensure that this mail is from me and has not been altered on the way to you. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: Digital signature URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090429/79f132e1/attachment-0005.bin>