gpt4 book ai didi

r - 图表上的多色文本

转载 作者:行者123 更新时间:2023-12-04 10:36:15 25 4
gpt4 key购买 nike

问候,

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com