# [R] Adding Text to a persp plot using specific coordinates

Uwe Ligges ligges at statistik.tu-dortmund.de
Thu Jul 5 12:16:46 CEST 2012

```
On 05.07.2012 06:45, Benjamin Dubreuil wrote:
>
> Hi folks,
>
> I'm experiencing some hassle to add some text on a persp plot...
>
> Here is the code to generate the persp plot:
> x <- seq(-1.95, 1.95, length = 30)
> y <- seq(-1.95, 1.95, length = 30)
> z <- outer(x, y, function(a,b) a*b^2)
> persp(x, y, z,xlim=c(-2,2),ylim=c(-2,2),zlim=c(-8,8), phi=30, theta=-30,nticks=8,ticktype="detailed")
>
> I've tried the text() function  :
> text(x=0,y=0,z=0,texts="O")
>
> It returns the following error message:
>> Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
>
> I've seen that text3d from the rgl library could add text on a plot3d object or a persp object.
> But when I try this:
> text3d(x=0,y=0,z=1,texts="O")
> The result is that R opens a new window with the string "O" printed in the new window. And no text is added to my previous persp plot.
>
> I've seen that maybe using trans3d would help but after many tries, I gave up. This function did not allow me to plot text with the specified coordinates.

Yes, trans3d:
x <- seq(-1.95, 1.95, length = 30)
y <- seq(-1.95, 1.95, length = 30)
z <- outer(x, y, function(a,b) a*b^2)
pmat <- persp(x, y, z,xlim=c(-2,2),ylim=c(-2,2),zlim=c(-8,8), phi=30,
theta=-30,nticks=8,ticktype="detailed")
text(trans3d(0,0,0,pmat), "Hello World!")

Best,
Uwe Ligges

>
> Any ideas on how adding some text or labels to an existing persp plot using the coordinates I've entered?
>
> Thanking you in anticipation.
>
> Dubreuil Benjamin
> Research Assistant in Bioinformatics
> Michnick Lab - Dept of Biochemistry - Université de Montréal
>
>
> 	[[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help