[英]how to plot three dimension data or four dimension data to filled contour plot or surface plot in R
ENV
R 3.3.2
当我有迷你数据1之类的数据时 :
rdn<-c(0.8,1.8,2.8)
tdn<-c(1,2,3,4,5,6,7,8,9)
idn<-matrix(c(0.3, 0.3, 0.3, 0.2, 0.2, 0.4, 0.1, 0.1, 0.5, 0, 0.2, 0.5, 0, 0.3, 0.6, 0, 0.4, 0.6, 0, 0.4, 0.6, 0, 0.5, 0.7, 0, 0.5, 0.7), nrow=9, ncol=3, byrow=T)
矩阵看起来像(3 * 9 = 27个数据元素):
0.3, 0.3, 0.3,
0.2, 0.2, 0.4,
0.1, 0.1, 0.5,
0, 0.2, 0.5,
0, 0.3, 0.6,
0, 0.4, 0.6,
0, 0.4, 0.6,
0, 0.5, 0.7,
0, 0.5, 0.7
然后我可以得到带有参数x,y,z的filled.contour。 x是tdn,y是rdn,z是矩阵。 我已经在几个月前使用fill.contour得到了这个 。 rdn和tdn仅用作x,y的标签。 矩阵似乎是轮廓线。 而且矩阵数据不是rdn和tdn的函数。
我当前的问题是:
如果我有三维数据迷你数据2
r1dn<-c(0.8,1.8,2.8)
r2dn<-c(0.8,1.8,2.8)
tdn<-c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9)
并且(3 * 3 * 9 = 81个数据元素):
0.8 1.8 2.8
0.8 1.8 2.8 0.8 1.8 2.8 0.8 1.8 2.8
--------------- 81 ---- elements ----------------------
0.3, 0.3, 0.3, 0.3, 0.3, 0.5, 0.3, 0.3, 0.3,
0.2, 0.2, 0.4, 0.2, 0.4, 0.4, 0.4, 0.2, 0.5,
0.1, 0.1, 0.5, 0.2, 0.3, 0.5, 0.4, 0.4, 0.5,
0, 0.2, 0.5, 0.2, 0.2, 0.6, 0.4, 0.5, 0.6,
0, 0.3, 0.6, 0.3, 0.3, 0.6, 0.5, 0.5, 0.7,
0, 0.4, 0.6, 0.2, 0.5, 0.7, 0.5, 0.6, 0.7,
0, 0.4, 0.6, 0, 0.5, 0.6, 0.5, 0.6, 0.9,
0, 0.5, 0.7, 0, 0.6, 0.8, 0.5, 0.7, 0.8,
0, 0.5, 0.7 0, 0.6, 0.8 0.5, 0.8, 0.9
我用谷歌搜索了许多表面和轮廓代码,但仍然找不到用于三维数据的代码。 如何在R中做到这一点? 假设x是r1dn,y是r2dn,z是tdn,那么三维数据(我的意思是81个元素数据)呢? ggplot是否可以绘制三维填充轮廓或曲面图? 还是其他替代解决方案?
我所期望的只是一个3d图,颜色平滑变化,并且没有网格。
看起来像:
接下来的三个数字没有网格
那些应该是3d填充轮廓或3d表面图。
谢谢你的时间。
编辑
展开所有数据迷你数据2后,它看起来像四个维度:
r1dn r2dn tdn fdn
x, y, z, f
0.8 0.8 0.1 0.3
0.8 0.8 0.2 0.2
0.8 0.8 0.3 0.1
0.8 0.8 0.4 0
0.8 0.8 0.5 0
0.8 0.8 0.6 0
0.8 0.8 0.7 0
0.8 0.8 0.8 0
0.8 0.8 0.9 0
0.8 1.8 0.1 0.3
0.8 1.8 0.2 0.2
0.8 1.8 0.3 0.1
0.8 1.8 0.4 0.2
0.8 1.8 0.5 0.3
0.8 1.8 0.6 0.4
0.8 1.8 0.7 0.4
0.8 1.8 0.8 0.5
0.8 1.8 0.9 0.5
0.8 2.8 0.1 0.3
0.8 2.8 0.2 0.4
0.8 2.8 0.3 0.5
0.8 2.8 0.4 0.5
0.8 2.8 0.5 0.6
0.8 2.8 0.6 0.6
0.8 2.8 0.7 0.6
0.8 2.8 0.8 0.7
0.8 2.8 0.9 0.7
1.8 0.8 0.1 0.3
1.8 0.8 0.2 0.2
1.8 0.8 0.3 0.2
1.8 0.8 0.4 0.2
1.8 0.8 0.5 0.3
1.8 0.8 0.6 0.2
1.8 0.8 0.7 0
1.8 0.8 0.8 0
1.8 0.8 0.9 0
1.8 1.8 0.1 0.3
1.8 1.8 0.2 0.4
1.8 1.8 0.3 0.3
1.8 1.8 0.4 0.2
1.8 1.8 0.5 0.3
1.8 1.8 0.6 0.5
1.8 1.8 0.7 0.5
1.8 1.8 0.8 0.6
1.8 1.8 0.9 0.6
1.8 2.8 0.1 0.5
1.8 2.8 0.2 0.4
1.8 2.8 0.3 0.5
1.8 2.8 0.4 0.6
1.8 2.8 0.5 0.6
1.8 2.8 0.6 0.7
1.8 2.8 0.7 0.6
1.8 2.8 0.8 0.8
1.8 2.8 0.9 0.8
2.8 0.8 0.1 0.3
2.8 0.8 0.2 0.4
2.8 0.8 0.3 0.4
2.8 0.8 0.4 0.4
2.8 0.8 0.5 0.5
2.8 0.8 0.6 0.5
2.8 0.8 0.7 0.5
2.8 0.8 0.8 0.5
2.8 0.8 0.9 0.5
2.8 1.8 0.1 0.3
2.8 1.8 0.2 0.2
2.8 1.8 0.3 0.4
2.8 1.8 0.4 0.5
2.8 1.8 0.5 0.5
2.8 1.8 0.6 0.6
2.8 1.8 0.7 0.6
2.8 1.8 0.8 0.7
2.8 1.8 0.9 0.8
2.8 2.8 0.1 0.3
2.8 2.8 0.2 0.5
2.8 2.8 0.3 0.5
2.8 2.8 0.4 0.6
2.8 2.8 0.5 0.7
2.8 2.8 0.6 0.7
2.8 2.8 0.7 0.9
2.8 2.8 0.8 0.8
2.8 2.8 0.9 0.9
好吧,数据迷你数据1可以展开为三维,也可以在2d图中通过fill.contour进行绘制,因此应该有一种3d fill.contour来绘制迷你数据2的方法吗?
这应该可以帮助您入门。 我尝试使用您的数据,但是当您扩展网格时,当您想要一个轮廓概述该体积的点时,您会得到一个体积的点。
require(akima)
require(rgl)
r1dn<-runif(5, min = 3, max = 10)
r2dn<-runif(5, min = 0, max = 5)
tdn<-rnorm(5, 0, 5)
#interp is from the akima package so you can work with non-square data in your contour
df <- as.data.frame(interp2xyz(interp(x=r1dn, y=r2dn, z=tdn)))
plot3d(df) # What it looks like in 3d
#what it looks like projected into 2d
ggplot(df, aes(x=x,y=y,z=z, fill=z)) +
geom_contour(binwidth=0.1, aes(color= ..level..)) +
theme_classic()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.