绘制在研发3D数据 [英] plotting 3D data in R

查看:259
本文介绍了绘制在研发3D数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个三维数据集:

 数据= data.frame(
    X =代表(C(0.1,0.2,0.3,0.4,0.5),每= 5),
    Y =代表(C(1,2,3,4,5),5)
)

数据$ Z = runif(
    25,
    分=(数据$ X *数据$ Y  -  0.1 *(参数$ X *数据$ Y)),
    最大=(数据$ X *数据$ Y + 0.1 *(参数$ X *数据$ Y))
)

数据
STR(数据)
 

和我想绘制,但řalwyas的内置函数给出错误

  

增加X和预期的'Y'值

 #### 3D绘图################################ ######################
#内置函数总是给错误
#增加'X'和'Y'值预期
演示(图)
图像(X =数据$ X,Y =数据$ Y,Z =数据$ Z)

演示(persp)
persp(数据$ X,数据$ Y,数据$ Z)

等高线(数据$ X,数据$ Y,数据$ Z)
 

当我在互联网上搜索,我发现,当X和Y值的组合是不是唯一的这条消息发生。但在这里,他们是独一无二的。

我尝试了一些其他图书馆和有它的工作原理没有问题。但我不喜欢重复的默认样式(内置的功能应该满足了我的期望)。

 ####的3D散点图################################ ######################
#尼斯地块没有表面的地图?
install.packages(scatterplot3d,依赖= TRUE)
库(scatterplot3d)
scatterplot3d(X =数据$ X,Y =数据$ Y,Z =数据$ Z)

#### 3D散点图############################################ ##########
#只是为了玩?
install.packages(RGL,依赖= TRUE)
库(RGL)
PLOT3D(X =数据$ X,Y =数据$ Y,Z =数据$ Z)
lines3d(X =数据$ X,Y =数据$ Y,Z =数据$ Z)
surface3d(X =数据$ X,Y =数据$ Y,Z =数据$ Z)
 

为什么我的数据集不接受内置功能?

感谢您的帮助,

斯文

解决方案

如果你正在使用的该网格间距和顺序不能保证被增加或独特的(希望的(X,Y,Z)的组合是独一无二的,至少,即使这些三元组是重复的),我会建议用于插入阿克玛包从不规则网格到常规的。

使用您的数据定义:

 库(阿克玛)
IM<  - 用(数据,插值(X,Y,Z))
与(1M,图像(X,Y,Z))
 

这应该工作不仅与图片但类似的功能也是如此。

请注意,默认的网格到你的数据被映射到由阿克玛::插值由跨越 X取值范围为40等间隔定义和值:

 >甲醛(阿克玛::插值)[C(XO,哟)
$ XO
SEQ(分(X),MAX(X),长度= 40)

$哟
SEQ(分(Y),最大值(Y),长度= 40)
 

不过,当然,这可以通过传递参数覆盖 XO 阿克玛::插值

I have a 3D dataset:

data = data.frame(
    x = rep( c(0.1, 0.2, 0.3, 0.4, 0.5), each=5),
    y = rep( c(1, 2, 3, 4, 5), 5)
)

data$z = runif(
    25,
    min = (data$x*data$y - 0.1 * (data$x*data$y)),
    max = (data$x*data$y + 0.1 * (data$x*data$y))
)

data
str(data)

And I want to plot it, but the built-in-functions of R alwyas give the error

increasing 'x' and 'y' values expected

# ### 3D Plots ######################################################
# built-in function always give the error
#    "increasing 'x' and 'y' values expected"
demo(image)
image(x = data$x, y = data$y, z = data$z)

demo(persp)
persp(data$x,data$y,data$z)

contour(data$x,data$y,data$z)

When I searched on the internet, I found that this message happens when combinations of X and Y values are not unique. But here they are unique.

I tried some other libraries and there it works without problems. But I don't like the default style of the plots (the built-in functions should fulfill my expectations).

# ### 3D Scatterplot ######################################################
# Nice plots without surface maps?
install.packages("scatterplot3d", dependencies = TRUE)
library(scatterplot3d)
scatterplot3d(x = data$x, y = data$y, z = data$z)

# ### 3D Scatterplot ######################################################
# Only to play around?
install.packages("rgl", dependencies = TRUE)
library(rgl)
plot3d(x = data$x, y = data$y, z = data$z)
lines3d(x = data$x, y = data$y, z = data$z)
surface3d(x = data$x, y = data$y, z = data$z)

Why are my datasets not accepted by the built-in functions?

Thanks for your help,

Sven

解决方案

If you're working with "real" data for which the grid intervals and sequence cannot be guaranteed to be increasing or unique (hopefully the (x,y,z) combinations are unique at least, even if these triples are duplicated), I would recommend the akima package for interpolating from an irregular grid to a regular one.

Using your definition of data:

library(akima)
im <- with(data,interp(x,y,z))
with(im,image(x,y,z))

And this should work not only with image but similar functions as well.

Note that the default grid to which your data is mapped to by akima::interp is defined by 40 equal intervals spanning the range of x and y values:

> formals(akima::interp)[c("xo","yo")]
$xo
seq(min(x), max(x), length = 40)

$yo
seq(min(y), max(y), length = 40)

But of course, this can be overridden by passing arguments xo and yo to akima::interp.

这篇关于绘制在研发3D数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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