data<-structure(list(words = c("The", "black", "dog", "jumped", "quickly",
"when", "the", "car", "started,", "but..."), cols = c(1, 9, 8,
4, 5, 2, 1, 7, 8, 1)), .Names = c("words", "cols"), row.names = c(NA,
-10L), class = "data.frame")
plot(0,0,type='n')
widths <- strwidth(data[,1])
spaces <- rep(strwidth(" "), length(widths)-1)
middle <- mean(par("usr")[1:2])
total <- sum(widths) + sum(spaces)
start <- c(0,cumsum(widths[-length(widths)] + spaces))
total <- sum(widths) + sum(spaces)
start <- start + middle - total/2
pos<-cbind(start,1)
colors<-rainbow(9)
text(pos,data[,1],col=colors[data[,2]],adj=0)
Я украл код у Дункана Мердока, связанный здесь: http://blog.revolutionanalytics.com/2009/01/multicolor-text-in-r.html