Вопрос

I'm trying to plot a function of two variables using the persp()function in R. This is what I have so far:

C_unab <- function(u1, u2) {
  return(u1 * u2)
}

x <- seq(0, 1, by = 0.1)
y <- seq(0, 1, by = 0.1)

z_1 <- outer(x,y, C_unab)

persp(x, y, z_1, theta = -60, phi = 25 ,shade = 0.7,expand = 0.8 , ltheta = -60, ticktype =     "detailed",
      xlab = "u1", ylab = "u2", zlab = "Phi", col="lightblue")

This works fine. However, I would like the "1" and "2" that appear in the axis labels to be subscripted (i. e. as indices). I've looked around and found "plotmath". However that doesn't seem to work for pesp()and the documentation says:" Expressions can also be used for titles, subtitles and x- and y-axis labels (but not for axis labels on persp plots)."

I've also done a search around here but haven't found anything that works for me.

Any help would be appreciated!

Это было полезно?

Решение

You cannot use expressions with persp, ... a well documented limitation. The usual advice is to switch to lattice:

library(lattice)
png(); print( wireframe(z_1~x+y  ,data=data.frame(x=x, y=rep(y, each=length(x)), z_1=z_1) ,  
                         xlab=expression(u[1]), ylab=expression(u[2]), zlab = "Z") ); dev.off()

enter image description here

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top