Skip to content
Prev 67802 / 398506 Next

abbreviate or wrap dimname labels

Dear Mark and Mike,

I had a chance to speak with Mike this afternoon, and he explained to me, so
politely that I almost missed it, that I hadn't read his posting very
carefully. Sorry for that.

Anyway, here's an alternative solution, which I think will meet Mike's
needs:

abbrev <- function(text, width=10, split=" "){
    if (is.list(text)) return(lapply(text, abbrev, width=width,
split=split)) 
    if (length(text) > 1)
        return(as.vector(sapply(text, abbrev, width=width, split=split)))
    words <- strsplit(text, split=split)[[1]]
    words <- ifelse(nchar(words) <= width, words, 
        abbreviate(words, minlength=width))
    words <- paste(words, collapse=" ")
    paste(strwrap(words, width=width), collapse="\n")
    }
$OccFather
[1] "Upper\nnonmanual" "Lower\nnonmanual" "Upper\nmanual"    "Lower\nmanual"

[5] "Farm"            

$OccSon
[1] "Upper\nnonmanual" "Lower\nnonmanual" "Upper\nmanual"    "Lower\nmanual"

[5] "Farm"
[1] "This is\na long\nlabel 1"  "This is\na long\nlabel 2" 
 [3] "This is\na long\nlabel 3"  "This is\na long\nlabel 4" 
 [5] "This is\na long\nlabel 5"  "This is\na long\nlabel 6" 
 [7] "This is\na long\nlabel 7"  "This is\na long\nlabel 8" 
 [9] "This is\na long\nlabel 9"  "This is\na long\nlabel 10"


I hope that this is more helpful than my original response.

John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
--------------------------------