r - R 中的 3D 绘图,更好的可见表面

标签 r plot

与我的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 图:

3d

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

所以我的第一个问题:

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

我的第二个问题:

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

编辑:另外:如何省略绘图中网格上的黑线?那么只有一个绿色的表面吗?这不是看起来更好了吗?

最佳答案

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

关于r - R 中的 3D 绘图,更好的可见表面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17252702/

相关文章:

python - 如何在 python 中绘制悬挂根图?

python - matplotlib/Python 中条形图的单独标记条

javascript - R Leaflet自定义属性字符串

r - 使用 lapply() 查找因子变量的百分比

r - 根据向量中的值过滤数据框行

r - R中轴刻度线与相应标签之间的距离

python - 显示渐近线的 pylab 图

Matlab 3D 矩阵图

r - 需要在网格中的图形中有序地排列 GAM 系数

python - 在 Matplotlib 中设置绘图 Canvas 的大小