Home > Software design >  Adding tick names to persp3d plot
Adding tick names to persp3d plot

Time:10-27

I have a persp3d plot showing default rates of companies based on the rating (AAA to CCC-) and time (years 1 to 20). I managed to show a line plot with the axes as numbers, however I would like to have them with the labels AAA to CCC- instead of 5,10,15. I also tried using surface3d() and bbox3d(), but I was not successful. line graph The code I am using now is:

Y <- c(1:dim(aggregate_row)[2]) # Tenors
X <- c(1:dim(aggregate_row)[1]) # Ratings
Z <- as.matrix.data.frame(aggregate_row)
cc <- colorRamp(rev(rainbow(10)))
Zsc <- (Z-min(Z))/diff(range(Z))
rgbvec2col <- function(x) do.call(rgb,c(as.list(x),list(max=500)))
colvec <- apply(cc(Zsc),1,rgbvec2col)
#surface3d(X,Y,Z,col=colvec)
#bbox3d(color=c("white","black"), xlab=c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "s", "t", "v"))
persp3d(X,Y,Z,col=colvec,xlab="Ratings",ylab="tenor",zlab="Default Rate",front="lines",back="lines")

CodePudding user response:

You didn't include your data, so I'll fake some:

aggregate_row <- matrix(1:400, 20, 20)

The way to get the axes you want is to tell persp3d not to draw axes, and then draw them yourself. For example,

library(rgl)

persp3d(X,Y,Z,col=colvec,xlab="Ratings",ylab="tenor",zlab="Default Rate",front="lines",back="lines",axes=FALSE)
box3d()
axis3d("x")    # the default
axis3d("y", at = c(5, 10, 15), labels = c("AAA", "BBB", "CCC"))
axis3d("z- ")  # move to a different edge

This produces the following picture:

enter image description here

  •  Tags:  
  • r rgl
  • Related