[R] Multicolor main title in a plot or mtext

Ottorino-Luca Pantani ottorino-luca.pantani at unifi.it
Thu Apr 22 18:18:56 CEST 2010


Dear R-users, the problem I'm facing today is to write a
multicolor main title in a plot.

I would like to have 3/4 colors to help people in the
audience to visually realize what is what in a 4x2 plot array

On top of each plot I would like to have two lines.
The 1st line will indicate what is plotted
The 2nd line will indicate a a reference

Graphically speaking I would like a result similar to this (simplified) one:

par(mfrow=c(2,4))
for(aux in 1:4){
plot(1,1)
mtext("1st treatm", cex=1, line=1.7, adj=0.1, col=1)
mtext("2nd treatm", cex=1, line=1.7, adj=0.5, col=2)
mtext("3rd treatm", cex=1, line=1.7, adj=0.9, col=3)
mtext("1st treatm", line=0.6, adj=0.1, col=1)
mtext("1st treatm", line=0.6, adj=0.5, col=1)
mtext("1st treatm", line=0.6, adj=0.9, col=1)
}
for(aux in 1:4){
plot(2,2)
mtext("1st treatm", cex=1, line=1.7, adj=0.1, col=1)
mtext("2nd treatm", cex=1, line=1.7, adj=0.5, col=2)
mtext("3rd treatm", cex=1, line=1.7, adj=0.9, col=3)
mtext("2nd treatm", line=0.6, adj=0.1, col=2)
mtext("2nd treatm", line=0.6, adj=0.5, col=2)
mtext("2nd treatm", line=0.6, adj=0.9, col=2)
}


The code above does more or less what I want and
I wrote it to simplify my explanation to you all.

But what I really need is  to put on top of each plot
an entire string with color embedded into, so to say.

A sort of "1st treatm 2nd treatm 3rd treatm" string with
informations able to colour the word "1st treatm" in black,
the word "2nd treatm"" in red and so on.

I need this because I have my descriptions in a vector like

c("1st treatm 2nd treatm 3rd treatm",
  "2nd treatm 3rd treatm 1st treatm",
   .......)

What I have in mind is something similar to the latex code
\color{black}{1st treatm} \color{red}{2nd treatm} \color{green}{3rd treatm}

Which pages of the R manual should I have to read to solve my problem ?

Thanks in advance
-- 
Ottorino-Luca Pantani, Università di Firenze
Dip.to di Scienze delle Produzioni Vegetali,
del Suolo e dell'Ambiente Forestale (DiPSA)



More information about the R-help mailing list