[R] Text with differents colors in a plot / Detecting if text exists
Jim Lemon
jim at bitwrit.com.au
Mon Jul 16 12:01:46 CEST 2007
Maja Schröter wrote:
> Hi everybody,
>
> I want to write some text in a plot.
>
> That's simple I know. But I want to make use of different colors.
>
> Eg. text(x,y,paste("Sunderland","high")).
>
> Then Sunderland should be black and "high" red.
>
> Has anyone an idea?
>
> By the way. I'm looking for a function or something similar, that can check whether there is text in some regions on the plot.
> Because I don't want to overwrite an existing text with a new one.
>
Hi Maja,
For your first question:
text(c(9,9),c(5,5),c("Sunderland","high"),
pos=c(2,4),offset=0.2,col=c("black","red"))
i.e., don't form a single string so that you can specify different
colors and positions for the two words.
For the second one, I am about to upload a new version of the plotrix
package that contains a function named "emptyspace". This tries to find
the largest rectangle on a plot that has nothing plotted within it.
Jim
More information about the R-help
mailing list