I draw the graph below using the plot3D
package of R. I would like to move a bit the z-axis label ($ f (y1, y2)
) off the axis values or leave it in horizontal. Does anyone know how I can proceed? Next the code:
library("plot3D")
#Function density probability
library(pbivnorm)
bsb <- function(t1,t2){
a1 <- sqrt(phi1/2)*(sqrt(((phi1+1)*t1)/(phi1*mu1))-sqrt(((phi1*mu1)/((phi1+1)*t1))))
a2 <- sqrt(phi2/2)*(sqrt(((phi2+1)*t2)/(phi2*mu2))-sqrt(((phi2*mu2)/((phi2+1)*t2))))
Phi2 <- pbivnorm(a1, a2, rho, recycle = TRUE)
b1 <- ((phi1+1)/(2*phi1*mu1))*sqrt(phi1/2)*(((phi1*mu1)/((phi1+1)*t1))^(1/2)+((phi1*mu1)/((phi1+1)*t1))^(3/2))
b2 <- ((phi2+1)/(2*phi2*mu2))*sqrt(phi2/2)*(((phi2*mu2)/((phi2+1)*t2))^(1/2)+((phi2*mu2)/((phi2+1)*t2))^(3/2))
fdp <- Phi2*b1*b2
return(fdp)
}
t1 <- seq(0.001,100,length=30)
t2 <- seq(0.001,20,length=40)
#Parameters
mu1=7
phi1=2
mu2=1
phi2=9
rho=0
z<-outer(t1,t2,bsb) # calculate density values
pmat=persp3D(t1, t2, z,
main="",xlab="$y_{1}$",ylab="$y_{2}$",zlab="$f(y_{1},y_{2})$",cex.axis=1,cex.lab=1,
col = "gray10",border = "gray40",
theta=50, phi=15,
expand=0.9,
d=2,
shade=0.3,
ticktype="detailed",
nticks=5,
facets=FALSE,contour = list(nlevels=10,col="gray35"), zlim= c(-0.1, 0.23), bty = "b2")
text(trans3d(0,7.3,0.173,pmat), "(b)",cex=1,col="black")
The picture looks like this:
I would like the following pictures:
The problem is with the sizing of your output window. If you use a larger one, the text will look better. For example, with a full screen window I get this from your original code:
You could also specify a lower dpi
value when you open the window if your graphics device supports that. For example, if I use dev.new(dpi = 50)
I get
I don't think there's a way to rotate labels in persp3D
, but you can draw the plot with no label, then use text
to add a label. You'll also need to increase the margin size on that side. For example,
par(mar = c(5.1, 9.1, 4.1, 2.1))
pmat <- persp3D(t1, t2, z, main="", xlab="$y_{1}$", ylab="$y_{2}$",
zlab="", cex.axis=1, cex.lab=1,
col = "gray10", border = "gray40",
theta=50, phi=15,
expand=0.9, d=2, shade=0.3,
ticktype="detailed", nticks=5,
facets=FALSE, contour = list(nlevels=10,col="gray35"),
zlim= c(-0.1, 0.23), bty = "b2")
text(trans3d(0,7.3,0.173,pmat), "(b)", cex=1, col="black")
text(trans3d(0,-3,0.05,pmat), label= "$f(y_{1},y_{2})$",
cex=1, col="black", xpd=NA, pos=2)
This gives me: