multicolor text on chart

后端 未结 2 1743
生来不讨喜
生来不讨喜 2020-12-11 23:00

Greetings,

I need to display multicolor text on my chart for example

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

txt <- paste(early, ontime, la         


        
2条回答
  •  既然无缘
    2020-12-11 23:38

    How about this code written by 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")) 
    

提交回复
热议问题