3d plot in R, better visible surface

后端 未结 1 1205
南方客
南方客 2021-01-22 00:55

With my data I created with the following code:

library(rugarch)
library(fGarch)

fd <- as.data.frame(modelfit, which = \'density\')

color <- rgb(85, 141,          


        
相关标签:
1条回答
  • 2021-01-22 01:30

    You can try setting shade=1 and border=NA in the persp call.

    Showing dates is a bit trickier, but can be done by hiding axes using axes=FALSE and redrawing them by finding opportune coordinates with the trans3d function.

    This would give something like:

    persp.mat <- persp(x, y, z, theta=50, phi=25, expand=0.75, col=color,
          ticktype="detailed", xlab="", ylab="time", zlab="density",
          shade=.4, border=NA, axes=F)
    
    # The coords at which we want ticks
    x.ticks <- seq(-0.2, 0.2, 0.1)
    # Transform them in 3D
    x.3d <- trans3d(x.ticks, 0, 0, persp.mat)
    x.3d.1 <- trans3d(x.ticks, 0, -2, persp.mat)
    # The coordinates for the text
    x.3d.labels <- trans3d(x.ticks, -60, -3, persp.mat)
    # Draw the axis ticks
    segments(x.3d$x, x.3d$y, x.3d.1$x, x.3d.1$y)
    # Write the labels
    text(x.3d.labels$x, x.3d.labels$y, x.ticks, cex=0.8)
    
    # Do the same for the other axes, customize the text labels
    # to write dates
    
    y.ticks <- seq(0, 2000, 500)
    # Or whatever you like...
    y.labels <- c("2009", "2010", "2011", "2012", "2013")
    y.3d <- trans3d(0.2, y.ticks, 0, persp.mat)
    y.3d.1 <- trans3d(0.2, y.ticks, -2, persp.mat)
    y.3d.labels <- trans3d(0.22, y.ticks, -3, persp.mat)
    segments(y.3d$x, y.3d$y, y.3d.1$x, y.3d.1$y)
    text(y.3d.labels$x, y.3d.labels$y, y.labels, cex=0.8)
    
    0 讨论(0)
提交回复
热议问题