0

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

Hew123
  • 63
  • 5
  • Your code does not produce a plot identical to the one you posted. The font size of the values on the axes are much smaller (and not crowded) when I run your code. There is also a type in "\u03b2\u209b" and your margins are too small. Are you printing the plot to a device other than the console? – dcarlson Dec 12 '22 at 04:05
  • Hi dcarlson, thanks for the comment! I am printing the plot to the console and not to any other device. Eventhough I tried removing the part, (xlab = "\u03b2\u209b", ylab = "\u03b3\u2090"), it doesn't seem to make a difference. – Hew123 Dec 12 '22 at 04:55

1 Answers1

1

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.

dcarlson
  • 10,936
  • 2
  • 15
  • 18
  • Platform: x86_64-w64-mingw32, R version: 4.2.2 (2022-10-31 ucrt), Version of plot3D: 1.4, Operation system: Windows 11 – Hew123 Dec 12 '22 at 17:12
  • Hi dcarlson, thank you so much! I made the suggested changes, and it improved things to a considerable extent. I will put the new graph as an edit. Thanks again! – Hew123 Dec 12 '22 at 17:18