图表上的多色文本

ily*_*lya 3 r

问候,

我需要在我的图表上显示多色文本

early <- 30
ontime <- 70
late <- 25

txt <- paste(early, ontime, late, sep='/')
plot(1:2, type='n')
text(1.5, 1.5, txt)
Run Code Online (Sandbox Code Playgroud)

我需要早期,正常时间,晚期txt的值,分别为蓝色,绿色和红色.

我在标题中找到了关于多色文本的帖子,但是我无法使其适应我的问题 http://blog.revolutionanalytics.com/2009/01/multicolor-text-in-r.html

谢谢您的帮助

Rom*_*rik 5

这个代码是由Jim Lemon写的怎么样?

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")) 
Run Code Online (Sandbox Code Playgroud)