[R] title: words in different colors?
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Thu Jan 22 18:45:00 CET 2009
Here's my version of the technicolor title function:
multiTitle <- function(...){
###
### multi-coloured title
###
### examples:
### multiTitle(color="red","Traffic",
### color="orange"," light ",
### color="green","signal")
###
### - note triple backslashes needed for embedding quotes:
###
### multiTitle(color="orange","Hello ",
### color="red"," \\\"world\\\"!")
###
### Barry Rowlingson <b.rowlingson at lancaster.ac.uk>
###
l = list(...)
ic = names(l)=='color'
colors = unique(unlist(l[ic]))
for(i in colors){
color=par()$col.main
strings=c()
for(il in 1:length(l)){
p = l[[il]]
if(ic[il]){ # if this is a color:
if(p==i){ # if it's the current color
current=TRUE
}else{
current=FALSE
}
}else{ # it's some text
if(current){
# set as text
strings = c(strings,paste('"',p,'"',sep=""))
}else{
# set as phantom
strings = c(strings,paste("phantom(\"",p,"\")",sep=""))
}
}
} # next item
## now plot this color
prod=paste(strings,collapse="*")
express = paste("expression(",prod,")",sep="")
e=eval(parse(text=express))
title(e,col.main=i)
} # next color
return()
}
More information about the R-help
mailing list