2017-04-10 245 views
0

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是矩陣。 I already get this several month ago using filled.contour。 rdn和tdn只能作爲x,y的標籤。矩陣似乎是看起來輪廓線。矩陣數據不是rdn和tdn的函數。

enter image description here

我現在的問題是:

如果我有三個維度數據迷你數據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可以繪製三維填充輪廓或曲面圖嗎?還是另一種替代方案?

我所期望的是一個三維繪圖,顏色變化平穩,沒有網格。

的樣子:

enter image description here

無網格接下來的三個數字

enter image description here

enter image description here

enter image description here

那些應該是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既可以展開,以三維並且可以通過填充.contour繪製在2D圖中,所以應該有一種填充3d的方式。等高線圖迷你數據2對不對?

回答

0

這應該讓你開始。我試圖使用你的數據,但是當你展開網格時,當你想要一個表面勾畫出音量時,你會得到一定數量的點。

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() 
+0

interp2xyz似乎使矩陣數據作爲x,y,z的函數?但是,我的數據矩陣不是x,y,z的函數。 –