R中的曲面图类似于gnuplot中的曲面图 [英] Surface plot in R similar to the one from gnuplot

查看:58
本文介绍了R中的曲面图类似于gnuplot中的曲面图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用R语言,现在我在大多数2d图中都使用R.现在,我想使用R生成3d图.我有来自工具的x,y,z数据,直到现在我都使用gnuplot中的splot生成表面图.我想使用R来生成类似于gnuplot给定的一个散点图的表面散点图.我看到的问题是,生成3d图R要求数据为矩阵格式,但我的数据不是该格式.我的问题是,如果gnuplot能够从数据生成图,为什么R无法做到这一点.我确定我缺少什么,请帮助我

I recently started using R language and now i am using R for most of my 2d plots. Now, I want to use R for generating 3d plots. I have x, y, z data coming from a tool, till now i was using splot in gnuplot to generate a surface plot. I want to use R for generating a surface plot similar to the one splot in gnuplot gives. Problem i see is, to generate a 3d plot R requires data to be in matrix format but my data is not in that format. My question is, if gnuplot is able to generate a plot from the data why R cant do it. I am sure i am missing something, please help me

这是gnuplot的情节

Here is the plot from gnuplot

这是数据

17.46 537.74 0.8
18.36 537.74 1.6
19.26 537.74 1.3
19.395 537.74 1.7
21.015 537.74 1.9
35.46 475.26 1.2
36.36 475.26 0.8
37.395 475.26 0.9
39.96 475.26 0.6
43.56 475.26 1

推荐答案

我是raster软件包的粉丝,这已经不是什么秘密了.它带有使用rgl包的plot方法.这些图像可以让人眼前一亮.

It's no secret that I'm a raster package fan. It comes with a plot method that uses rgl package. The images can be quite the eye-full.

这是?raster::plot3D中的示例

编辑

这是一个如何使用三列矩阵绘制表面的示例.此示例看起来像《真人快打》中的阶段性死亡陷阱.如果您正在寻找内核平滑功能,那么就值得考虑一下自己的问题.

Here's an example of how to plot a surface using a matrix with three columns. This example looks like stage death trap in Mortal Combat. If you're looking for kernel smoothing, then that merits its own question.

library(rgl)
library(raster)
x <- sample(-500:500, 1000, replace = TRUE)
y <- sample(-500:500, 1000, replace = TRUE)
z <- rnorm(500, 10, 20)
df <- cbind(x, y, z)

rst <- raster(ncols = 100, nrows = 100, xmn = -100, xmx = 100, ymn = -100, ymx = 100)
rst2 <- rasterize(x = df[,1:2], y = rst, df[, 3])
plot3D(rst2)

这篇关于R中的曲面图类似于gnuplot中的曲面图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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