Hi does somebody know how to plot single letters in a text in different colours? example 1: I would like to add the word "ABC" to a figure. Thereby each letter should have a different colour. text(x,y,"ABC", col=c(1,2,3)) # this does not work example 2: I would like to add the name of a parameter p with an index i to a figure. The index i should be in red, whereas the rest of the text should be in black. text(x,y, expression(p[i])) Looking forward to your answers! Fr?nzi
2008/8/28 Fr?nzi Korner <fraenzi.korner at oikostat.ch>:> example 1: > I would like to add the word "ABC" to a figure. Thereby each letter should > have a different colour. > > text(x,y,"ABC", col=c(1,2,3)) # this does not work >kludge alert! How about: text(x,y,"ABC",col=3) text(x,y,"AB",col=2) text(x,y,"A",col=1) Basically this overlays three coloured texts to give the impression of individual coloured letters. This may or may not be practical for your real application. It's also possible that if you print this your printer will end up printing "A" with a mix of colours 1, 2 and 3. If your font is monospaced you could do it with text(x,y," C",col=3), but in a pretty font the letters AB wont have the same width as two spaces. Barry
See ?strwidth, e.g. plot(1) text(1.1, 1.1, "A") text(1.1 + strwidth("A"), 1.1, "B", col = 2) text(1.1 + strwidth("AB"), 1.1, "C", col = 3) On Thu, Aug 28, 2008 at 7:33 AM, Fr?nzi Korner <fraenzi.korner at oikostat.ch> wrote:> Hi > > does somebody know how to plot single letters in a text in different > colours? > > example 1: > I would like to add the word "ABC" to a figure. Thereby each letter should > have a different colour. > > text(x,y,"ABC", col=c(1,2,3)) # this does not work > > > > example 2: > I would like to add the name of a parameter p with an index i to a figure. > The index i should be in red, whereas the rest of the text should be in > black. > > text(x,y, expression(p[i])) > > > Looking forward to your answers! > > Fr?nzi > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >