Andrew Yee wrote:
> Hi, I'm interested in using mtext(), but with the option of having multiple
> colors in the same line of text.
>
> For example, creating a line of text where:
>
> Red is red and blue is blue
>
> How do you create a text argument that lets you do this within mtext()?
>
You can do something like this with "text" and then use xpd=TRUE to use
it outside the plot. I think it would be more fiddly trying to use "mtext".
concat.text<-function(x,y,txt,col) {
thisx<-x
for(txtstr in 1:length(txt)) {
text(thisx,y,txt[txtstr],col=col[txtstr],adj=0)
thisx<-thisx+strwidth(txt[txtstr])
}
}
plot(0,xlim=c(0,1),ylim=c(0,1),type="n")
ctext<-c("Roses are ","red, ","violets are ","purple")
concat.text(0,0.5,ctext,col=c("black","red","black","purple"))
Jim
______________________________________________
[email protected] 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.