プロット上のテキストの文字を一部分だけ色を変えたい

ABCDみたいなことをしたいが、文字をそのままtext関数で配置すると、一色しか使えない。
というわけで一文字ずつ着色するのだが、そうすると文字の配置がずれる。
なのでsubstitutephantomを使って文字と同じ幅の空白を作って無理やり文字を配置する。

txt <- "RAINBOW"
w <- strsplit(txt, "")[[1]]
cols <- rainbow(length(w))
# 地道に書いて配置してみる
cex <- 2
par(mar=c(1, 1, 1, 1))
plot(1, type="n", frame=FALSE, xaxt="n", yaxt="n", xlab="", ylab="")
pa <- par()$usr
x <- mean(pa[1:2])
y <- seq(pa[4], pa[3], length=length(w)+2)
text(x, y[1], txt, cex=cex, xpd=TRUE)
text(x, y[2], substitute(phantom("")*"R"*phantom("AINBOW")), cex=cex, col=cols[1])
text(x, y[3], substitute(phantom("R")*"A"*phantom("INBOW")), cex=cex, col=cols[2])
text(x, y[4], substitute(phantom("RA")*"I"*phantom("NBOW")), cex=cex, col=cols[3])
text(x, y[5], substitute(phantom("RAI")*"N"*phantom("BOW")), cex=cex, col=cols[4])
text(x, y[6], substitute(phantom("RAIN")*"B"*phantom("OW")), cex=cex, col=cols[5])
text(x, y[7], substitute(phantom("RAINB")*"O"*phantom("W")), cex=cex, col=cols[6])
text(x, y[8], substitute(phantom("RAINBO")*"W"*phantom("")), cex=cex, col=cols[7])

# いっぺんに
for(i in seq(w)){
  w0 <- c("", w, "")
  hoge <- substitute(phantom(w1)*w2*phantom(w3), list(w1=paste0(w0[1:i], collapse=""), w2=w0[i+1], w3=paste0(w0[(i+2):(length(w)+2)], collapse="")))
  text(x, y[9], hoge, cex=cex, col=cols[i], xpd=TRUE)
}