Stretching axes in perspbox - 3D Plots in R

93 Views Asked by At

I have been trying to replicate a 3D graph that I saw on a paper that I read for a class project. I recently posted a question asking about possible ways of plotting it and I received amazing support on that. However, I am still struggling to figure out how to stretch the axes to get rid of the cluttering of the values on the axes (image below).

enter image description here

The code that I used is as follows.

library(plot3D)
par(mar=c(1,1,1,1))

R_0 <- function(beta_s, gamma_a, alpha_a = 0.4775, alpha_u = 0.695,
                mu = 0.062, q_i = 0.078, eta_i = 0.009, eta_u = 0.05) {
  
  A <- beta_s * alpha_a / (gamma_a + mu) 
  B <- beta_s * alpha_u * gamma_a * (1 - q_i) / ((gamma_a + mu) * (eta_u + mu))
  A + B
}

beta <- gamma <- seq(0, 0.4, length.out = 100)

R <- outer(beta, gamma, R_0)

#Adding an empty perspbox

perspbox(beta, gamma, z = R, theta = -50, ticktype = "detailed",
         col.grid = "gray85", bty = "u",
         xlab = "\u03b2\u209b", ylab = "\u03b3\u2090")

pp <- persp3D(beta, gamma, z = R, theta = -50, add = TRUE)

#Horizontal plane-adding function

plane3D <- function(z, 
                    col = adjustcolor("blue", alpha.f = 0.2),
                    border = NA,
                    xlim = c(0,0.4), ylim = c(0, 0.4)) {
  dd <- expand.grid(x=xlim, y = ylim, z= z)
  rr <- with(dd, trans3D(x,y,z,pp))
  perm <- c(1,3,4,2)
  polygon(rr$x[perm], rr$y[perm], col = col, border = border)
}

#Adding planes

plane3D(1)
plane3D(2, col = adjustcolor("red", alpha.f = 0.2))

Any help would be greatly appreciated. Thanks a lot in advance!

The graph based on dcarlson's answer

enter image description here

1

There are 1 best solutions below

2
On

Running your code with two changes: xlab = "\u03b2\u2090" instead of xlab = "\u03b2\u209b" and changing par(mar=c(1.5, 2, 1.5, 2)) on Mac, I get this plot:

Plot

You need to provide more information on your computer's operating system and the versions of R and plot3D that you are using.