从多维数组制作3D散点图

时间:2015-05-18 13:04:42

标签: r multidimensional-array

我有一个3维hdf5文件,我想在R中绘制为散点图。

到目前为止我的代码似乎加载了数据就好了。但是散点图函数想要x,y,z作为参数,我不知道该告诉它:

$( "#2 div:first-child" ).height(result11);

理想情况下,我希望R具有与numpy的非零()函数相当的东西,它为您提供所有非零值的坐标。

更新,也许这里取得了一些进展:

> source("http://bioconductor.org/biocLite.R")
> biocLite("rhdf5")
> library(rhdf5)
> mydata <- h5read('/Users/greg/1611_data.h5','dataset_1')
> str(mydata)
 int [1:194, 1:627, 1:269] 0 0 0 0 0 0 0 0 0 0 ...
> install.packages("scatterplot3d")
> library(scatterplot3d)
> scatterplot3d(mydata)
Error in xyz.coords(x = x, y = y, z = z, xlab = xlabel, ylab = ylabel,  : 
  'x', 'y' and 'z' lengths differ

但现在我不确定如何引用dim1等。

1 个答案:

答案 0 :(得分:1)

这似乎有效:

> source("http://bioconductor.org/biocLite.R")
> biocLite("rhdf5")
> library(rhdf5)
> mydata <- h5read('/Users/greg/1611_data.h5','dataset_1')
> str(mydata)
 int [1:194, 1:627, 1:269] 0 0 0 0 0 0 0 0 0 0 ...
> install.packages("scatterplot3d")
> library(scatterplot3d)
> coords <-which(mydata!=0, arr.ind=T)
> scatterplot3d(coords[,'dim1'],coords[,'dim2'],coords[,'dim3'])
相关问题