简体   繁体   English

如何将此数据绘制为 R 中的曲面图?

[英]How can I plot this data as a surface plot in R?

I'm trying to plot the following data as a surface plot.我正在尝试将以下数据绘制为曲面图。 The mesh library or persp3D seems to do what I want, but it seems I cannot find the correct way to input my data.网格库或 persp3D 似乎可以做我想要的,但似乎我找不到输入数据的正确方法。 I pasted some sample data below.我在下面粘贴了一些示例数据。

  V1   V2   V3
1 1.01 1.30 -113.7410   
2 1.01 1.25 -113.7540   
3 1.01 1.22 -113.7589    
4 1.01 1.20 -113.7605  
5 1.03 1.30 -113.7458  
6 1.03 1.25 -113.7590   
7 1.01 1.20 -113.7605

Thanks!谢谢!

Your sample data doesn't make sense, you basically need to make a grid of points (equally spaced!) on your x, y axis and a single z coordinate.您的示例数据没有意义,您基本上需要在 x、y 轴和单个 z 坐标上制作一个点网格(等距!)。 I suppose you could use interpolation to get some kind of surface plot based on your data.我想您可以使用插值来根据您的数据获得某种表面图。

In the example below I've used interp from akima to interpolate the values based on the mean, and it will produce a grid of points in the format that you're after.在下面的示例中,我使用interp akima来根据平均值对值进行插值,它会以您所追求的格式生成点网格。

library(rgl)
library(akima)

dat<-data.frame(V1=c(1.01,1.01,1.01,1.01,1.03,1.03,1.01),
              V2=c(1.30,1.25,1.22,1.20,1.30,1.25,1.20),
              V3=c(-113.7410,-113.7540,-113.7589,-113.7605,-113.7458,-113.7590,-113.7605))

s = interp(dat$V1, dat$V2, dat$V3, duplicate="mean")
persp3d(s$x, s$y, s$z)

Output:输出:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM