persp3d图的格式 [英] Formatting of persp3d plot

查看:89
本文介绍了persp3d图的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下3d图:

使用我的数据,我使用以下代码创建了该数据:

With my data I created it with the following code:

library(rugarch)
library(rgl)
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)
persp3d(x, y, z, theta=50, phi=25, expand=0.75, col=color,
      ticktype="detailed", xlab="", ylab="time", zlab="",axes=TRUE)

如何根据z值获得颜色?我看了不同的解决方案,例如此一个,但我无法创建着色在这种情况下取​​决于z值. 根据此线程的解决方案将是以下内容:

How can I get a coloring depending on the z values? I looked at different solutions, e.g. this one, but I could not create the coloring depending on the z values in this case. The solution according to this thread would be the following:

nrz <- nrow(z)
ncz <- ncol(z)
jet.colors <- colorRampPalette( c("#ffcccc", "#cc0000") ) 
# Generate the desired number of colors from this palette
nbcol <- 100
color <- jet.colors(nbcol)

# Compute the z-value at the facet centres
zfacet <- z[-1, -1] + z[-1, -ncz] + z[-nrz, -1] + z[-nrz, -ncz]
# Recode facet z-values into color indices
facetcol <- cut(zfacet, nbcol)

  persp3d(x, y, z, theta=50, phi=25, expand=0.75, col=color[facetcol],
          ticktype="detailed", xlab="", ylab="time", zlab="",axes=TRUE)

但是,这不会给出良好的结果,因为它不会为绘图添加适当的颜色.我想让表面的尖刺成为例如以红色表示,低值例如呈蓝色且平滑过渡良好,但是这种颜色可以使切片着色,因此取决于时间吗?因此,极大的尖峰应在其尖峰处涂成红色,并在底部标出值,例如绿色.我怎么能得到这个?

But this does not give a good result, since it does not color the plot appropriate. I want to have the spikes of my surface to be e.g. in red and the low values to be e.g. in blue with a nice smooth transition, but this kind of colors the slices, so depending on the time? So extreme large spikes should be colored at their spikes in red and values at the bottom e.g. in green. How can I get this?

我找到了我上一个关于轴上日期的问题的解决方案,剩下的唯一问题是取决于z值的适当着色.

I found a solution to my previous question about the date on the axis, the only problem left, is an appropriate coloring dependent on the z values.

推荐答案

尝试一下:

nbcol = 100
color = rev(rainbow(nbcol, start = 0/6, end = 4/6))
zcol  = cut(z, nbcol)
persp3d(x, y, z, theta=50, phi=25, expand=0.75, col=color[zcol],
        ticktype="detailed", xlab="", ylab="time", zlab="",axes=TRUE)

如果您希望按时间着色(因此尖峰始终为红色),则可以为每个时间片设置着色:

If you want the coloring to be by time (so spikes are always red) you can set the coloring for each time slice:

mycut = function(x, breaks) as.numeric(cut(x=x, breaks=breaks)) # to combine different factors
zcol2 = as.numeric(apply(z,2, mycut, breaks=nbcol)) 
persp3d(x, y, z, theta=50, phi=25, expand=0.75, col=color[zcol2],
        ticktype="detailed", xlab="", ylab="time", zlab="",axes=TRUE)

您已经知道如何正确编辑轴.

You already know how to edit the axes properly.

这篇关于persp3d图的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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