2

I am trying to define my z-axis label as R0 in plot3D, below are my code, I am using expression for my zlab, but I get the result as in the image attached here.

library(plot3D)
lambda <- 1/12
sigma <- 0.4
gamma <- 0.4
beta <- 0.00007
c <-0.0034
m <- (0.08/12)
mu <- 1
f <- function(x,y){(beta*(x*(m+lambda)/((m+c)*(m+lambda)+m*y))*sigma*gamma)/((m+sigma+c)*(m+mu+c))}
x <- seq(0,1000,10)
y <- seq(0,1,0.01)
z <- outer(x,y,f)
persp3D(x=x, y=y, z=z, 
    col.palette = heat.colors, 
    phi = 20, theta = 300, nticks=4,
    zlab=expression('R'[0]), ylab = "k", xlab="A", 
    xlim = c(0, 1000), 
    ylim = c(0, 1), 
    zlim = c(0, 3.5),
    box = TRUE, border = NA, shade = .4,ticktype="detailed",scale= TRUE, expand = 0.5)

my 3D plot

Werner Hertzog
  • 2,002
  • 3
  • 24
  • 36
Ella Taib
  • 63
  • 4
  • The help page of `persp`, which `plot3D` is based on, has under `xlab, ylab, zlab`: These must be character strings; expressions are not accepted. The issue is fonts. https://stackoverflow.com/questions/29988230/using-expression-in-r-rgl-axis-labels – Edward Mar 30 '20 at 07:38

1 Answers1

4

text3D() allows expressions to display mathematical annotation. Remember to set the graphical parameter xpd to TRUE, or the text will be clipped when out of the "plot" region.

persp3D(..., zlab = "", ...) # blank zlab
par(xpd = TRUE)
text3D(0, 1.4, 1, expression(R[0]), add = TRUE)
Darren Tsai
  • 32,117
  • 5
  • 21
  • 51