R 中的 3d 绘图,更好的可见表面 [英] 3d plot in R, better visible surface

查看:36
本文介绍了R 中的 3d 绘图,更好的可见表面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

以下 3d 绘图:

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

As you can see the surface looks messy.

所以我的第一个问题:

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

How can I get a better visible surface?

我的第二个问题:

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

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?

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

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?

推荐答案

你可以尝试在persp中设置shade=1border=NA代码>调用.

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

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

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.

这将给出类似:

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)

这篇关于R 中的 3d 绘图,更好的可见表面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆