使用 R 绘制具有等值线图叠加的 3D 曲面图
我有一个三元组数据集(X,Y,Z点),我想用R来绘制。
我想从数据创建一个曲面图,并在曲面图上叠加一个等高线图,以便创建等高线图的印象是表面图的“阴影”或投影。等高线图将出现在曲面图下方。
我的数据集看起来有点像这样:
Axis | Data Type
-------------------
X | Date value
Y | Float value
Z | Float value
我怎样才能实现这个目标?
I have a 3-tuple data set (X,Y,Z points) that I want to plot using R.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:
我刚刚看到您指出您的维度之一是日期。在这种情况下,看看 Jeff Ryan 的 ChartSeries3d,它旨在绘制 3 维图表时间序列。在这里,他显示了随时间变化的收益率曲线:
原始答案:
据我了解,您希望 countour 地图成为 3D 曲面图下方平面上的投影。我不认为除了创建两个图然后将它们组合之外,还有其他简单的方法可以做到这一点。您可能发现空间视图对此很有帮助。
有两个用于 3D 绘图的主要 R 包:rgl< /strong> (或者您可以使用相关的 misc3d 包)和 <强>scatterplot3d。
rgl
rgl 包使用 OpenGL 创建交互式 3D 绘图(在 rgl 网站上了解更多信息)。下面是使用
surface3d
函数的示例:alpha 参数使该表面部分透明。现在您已经有了一个交互式 3D 曲面图,并且您想要在下面创建一个计数地图。 rgl 允许您向现有图像添加更多绘图:
在此表面中,我设置高度=1,以便我们在另一个表面下方有一个平面。最终看起来像这样,并且可以用鼠标旋转:
scatterplot3d
scatterplot3d 有点像 R 中的其他绘图函数(阅读小插图)。这是一个简单的示例:
在这种情况下,您将需要覆盖图像。 R-Wiki 有一篇关于创建的很好的帖子半透明的背景图像。
Edit:
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:
Original Answer:
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.
There are two primary R packages for 3D plotting: rgl (or you can use the related misc3d package) and scatterplot3d.
rgl
The rgl package uses OpenGL to create interactive 3D plots (read more on the rgl website). Here's an example using the
surface3d
function: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:
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 is a little more like other plotting functions in R (read the vignette). Here's a simple example:
In this case, you will need to overlay the images. The R-Wiki has a nice post on creating a tanslucent background image.