问候,
例如,我需要在我的图表上显示多色文本
early <- 30
ontime <- 70
late <- 25
txt <- paste(early, ontime, late, sep='/')
plot(1:2, type='n')
text(1.5, 1.5, txt)
我需要 early、ontime、late in txt 的值,分别为蓝色、绿色和红色。
我在标题中找到了以下关于多色文本的帖子,但是我无法使其适应我的问题 http://blog.revolutionanalytics.com/2009/01/multicolor-text-in-r.html
谢谢你的帮助
最佳答案
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"))
关于r - 图表上的多色文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3258101/