2

With my data I created with the following code:

library(rugarch)
library(fGarch)

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

color <- rgb(85, 141, 85, maxColorValue=255)

x <- seq(-0.2, 0.2, length=100)
y <-c(1:2318)


f <- function(s, t) {
 dged(s,mean=fd[t,'Mu'],sd=fd[t,'Sigma'],nu=fd[t,'Shape'])

}

z <- outer(x, y, f)

persp(x, y, z, theta=50, phi=25, expand=0.75, col=color,
      ticktype="detailed", xlab="", ylab="time", zlab="density")

the following 3d plot:

3d

As you can see the surface looks messy.

So my first question:

How can I get a better visible surface?

And my second question:

How can I get the real dates on my axis? Currently I use c(1:2318), but in my original data I can see the dates in the rownames via command fd. So how can I get those dates on my axis?

Edit: Also: How can I omitt the black lines on the grid in my plot? So that there is just a green surface? Wouldn't that already look better?

Community
  • 1
  • 1
user1690846
  • 255
  • 1
  • 2
  • 11

1 Answers1

3

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)
nico
  • 50,859
  • 17
  • 87
  • 112
  • I reuploaded it, now it should work. Make sure to have the current version of rugarch (>= 3.00) and load the library. – user1690846 Jun 22 '13 at 16:32
  • @user1690846: sorry, my bad, did not see the link the first time. I'll update the answer in a minute :) – nico Jun 22 '13 at 16:33
  • ok, if you tell me how I can do the trick with the dates this would already help me! – user1690846 Jun 22 '13 at 16:36
  • If the following would be possible, I think it would solve the problem: Is there a preimplemented way to use different colors? So not only green, but for the high values e.g. red and then declining in the color to black for low values? Than the surface would be better visible. So something like 'shade=colors'? – user1690846 Jun 22 '13 at 16:41
  • @user1690846: updated the answer. As for the colors, I have to think about it for a second, I am sure you can... – nico Jun 22 '13 at 16:53
  • thanks for your first hint, but your axis starts at 2010 but my data already at 2004? The scaling somehow seems to be wrong? Because in your plot it looks like my data starts at 2009? (my compuational skills in R are limited) – user1690846 Jun 22 '13 at 17:04
  • @user1690846: oh, I just put some random dates. The `y.labels` variable holds the labels, change it to whatever you want. For the colors you may want to have a look at the solutions proposed here: http://stackoverflow.com/questions/10357002/create-3d-plot-colored-according-to-the-z-axis – nico Jun 22 '13 at 17:24