绘制一个三维曲面图与等高线图叠加,基于R [英] Plotting a 3D surface plot with contour map overlay, using R

查看:3094
本文介绍了绘制一个三维曲面图与等高线图叠加,基于R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个3元组数据集(X,Y,Z点),我想用r跟踪。

I have a 3-tuple data set (X,Y,Z points) that I want to plot using R.

我要创建从数据表面图,并叠加到曲面图等高线图,从而创造了等高线图是从表面图的影子或投影的IM pression。等值线图是出现下面的表面图。

I want to create a surface plot from the data, and superimpose a contour map on the surface plot, so as to create the impression of the contour map being the "shadow" or projection from the surface plot. The contour map is to appear below the surface plot.

我的数据集看起来有点像这样的:

My data set looks somewhat like this:

Axis  |  Data Type
-------------------
X     |  Date value
Y     |  Float value
Z     |  Float value

我怎样才能做到这一点?

How can I achieve this?

推荐答案

编辑:

我刚才看到你指出你的一个维度是一个日期。在这种情况下,看看杰夫·瑞安的chartSeries3d 其目的是绘制三维的时间序列。在这里,他显示了收益率曲线随时间:

I just saw that you pointed out one of your dimensions is a date. In that case, have a look at Jeff Ryan's chartSeries3d which is designed to chart 3-dimensional time series. Here he shows the yield curve over time:

原来的答案:

据我了解,你想有一个countour图是对3D曲面图下方的平面上的投影。我不相信有一个简单的方法来做到这一点以外创建两个地块,然后将它们组合起来。您可以找到空间视图此的帮助。

As I understand it, you want a countour map to be the projection on the plane beneath the 3D surface plot. I don't believe that there's an easy way to do this other than creating the two plots and then combining them. You may find the spatial view helpful for this.

有两个主要的R封装的3D绘图: RGL (或者你可以使用相关的 misc3​​d 封装)和scatterplot3d

There are two primary R packages for 3D plotting: rgl (or you can use the related misc3d package) and scatterplot3d.

RGL

该RGL包使用OpenGL创建交互式3D绘图(更多的RGL网站)。下面是一个使用 surface3d 函数的例子:

The rgl package uses OpenGL to create interactive 3D plots (read more on the rgl website). Here's an example using the surface3d function:

library(rgl)
data(volcano)
z <- 2 * volcano # Exaggerate the relief
x <- 10 * (1:nrow(z)) # 10 meter spacing (S to N)
y <- 10 * (1:ncol(z)) # 10 meter spacing (E to W)
zlim <- range(z)
zlen <- zlim[2] - zlim[1] + 1
colorlut <- terrain.colors(zlen,alpha=0) # height color lookup table
col <- colorlut[ z-zlim[1]+1 ] # assign colors to heights for each point
open3d()
rgl.surface(x, y, z, color=col, alpha=0.75, back="lines")

阿尔法参数,使该表面部分透明。现在你有一个表面的互动3D图,并要下创建一个countour地图。 RGL允许你添加更多曲线到现有的图像:

The alpha parameter makes this surface partly transparent. Now you have an interactive 3D plot of a surface and you want to create a countour map underneath. rgl allows you add more plots to an existing image:

colorlut <- heat.colors(zlen,alpha=1) # use different colors for the contour map
col <- colorlut[ z-zlim[1]+1 ] 
rgl.surface(x, y, matrix(1, nrow(z), ncol(z)),color=col, back="fill")

在这面我设置的高度= 1,使我们有其他的表面之下的平面上。这最终看起来像这样,可以用鼠标旋转:

In this surface I set the heights=1 so that we have a plane underneath the other surface. This ends up looking like this, and can be rotated with a mouse:

scatterplot3d

scatterplot3d是有点像其它绘图函数在R(读小插曲)。这里有一个简单的例子:

scatterplot3d is a little more like other plotting functions in R (read the vignette). Here's a simple example:

temp <- seq(-pi, 0, length = 50)
x <- c(rep(1, 50) %*% t(cos(temp)))
y <- c(cos(temp) %*% t(sin(temp)))
z <- c(sin(temp) %*% t(sin(temp)))
scatterplot3d(x, y, z, highlight.3d=TRUE,
 col.axis="blue", col.grid="lightblue",
 main="scatterplot3d - 2", pch=20)

在这种情况下,你需要覆盖的图像。在R-维基对创建tanslucent背景图片

In this case, you will need to overlay the images. The R-Wiki has a nice post on creating a tanslucent background image.

这篇关于绘制一个三维曲面图与等高线图叠加,基于R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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