2013-06-22 60 views
2

随着我data我用下面的代码创建:3D绘图,更好的可见表面

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") 

以下3D图:

3d

正如你所看到的表面看起来凌乱。

所以我的第一个问题:

我怎样才能获得更好的可见表面?

我的第二个问题:

如何,我可以得到我的轴线真正的日期?目前我使用c(1:2318),但在我的原始数据 中,我可以通过命令fd查看rownames中的日期。那么我怎么能在我的轴上获得这些日期?

编辑:另外:我怎么能省略在我的情节网格上的黑线?所以只有一个绿色的表面?这不会看起来更好吗?

回答

3

您可以尝试在persp调用中设置shade=1border=NA

显示日期有点棘手,但可以通过使用axes=FALSE隐藏坐标轴并使用trans3d函数找到适当的坐标来重绘它们。

这将使类似:

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

我重新上传了它,现在它应该工作。确保使用当前版本的rugarch(> = 3.00)并加载库。 – user1690846

+0

@ user1690846:对不起,我的不好,第一次没有看到链接。我会在一分钟内更新答案:) – nico

+0

好吧,如果你告诉我如何能够做到这一点,这将已经帮助我! – user1690846