【问题标题】:3d plot in R, better visible surfaceR中的3d绘图,更好的可见表面
【发布时间】:2013-06-19 14:46:28
【问题描述】:

使用我的data,我使用以下代码创建:

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 图:

如您所见,表面看起来很乱。

所以我的第一个问题:

如何获得更好的可见表面?

还有我的第二个问题:

如何获取坐标轴上的真实日期?目前我使用 c(1:2318),但在我的原始数据中 我可以通过命令fd 查看行名中的日期。那么我怎样才能在我的轴上获得这些日期呢?

编辑:另外:我怎样才能在我的情节中省略网格上的黑线?所以只有一个绿色的表面?那不是已经更好看了吗?

【问题讨论】:

    标签: r plot


    【解决方案1】:

    您可以尝试在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)
    

    【讨论】:

    • 我重新上传了,现在应该可以了。确保拥有当前版本的 rugarch (>= 3.00) 并加载库。
    • @user1690846:对不起,我的错,第一次没有看到链接。我会在一分钟内更新答案:)
    • 好的,如果你告诉我如何处理日期,这已经对我有帮助了!
    • 如果以下可能,我认为它会解决问题:是否有预先实现的方式来使用不同的颜色?因此,不仅是绿色,而且对于高值,例如红色然后颜色下降到黑色以获得低值?比表面会更好看。那么像“shade=colors”这样的东西?
    • @user1690846:更新了答案。至于颜色,我得考虑一下,我相信你可以......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-31
    • 2011-11-25
    • 1970-01-01
    • 2021-04-04
    • 1970-01-01
    相关资源
    最近更新 更多