2016-12-14 158 views
1

我想繪製一個與此示例類似的圖(請參閱blow)。R:使用surface3d繪製矩陣文件中的3D繪圖幫助

enter image description here

這裏是我的數據集的例子。

z <- data.frame(round(runif(977,500,600))) 
    z_matrix <- t(matrix(z[0:(as.integer(length(z[,])/10) * 10),],as.integer(length(z[,])/10),10)) 

我也能使用ggplot其他一些2D或3D繪圖,image2D,persp和persp3d,但上述3D圖的例子相比,這些地塊是不是在找大。

我試過使用surface3d,但我得到了錯誤。我也嘗試使用grid.to.xyz將矩陣格式轉換爲x.y.z格式,但似乎格式不正確。

此外,顏色梯度隨着各種數據集中z的範圍而變化。我需要「修復」漸變的顏色模式並將其應用於其他數據集,以便它們具有可比性。

我的問題:

  1. 如何產生使用surface3d或PLOT3D格式的矩陣集3D繪圖?
  2. 如何將顏色漸變的模式修復爲特定的值範圍?

感謝您的幫助!

+1

請在「五十方式吸引用戶使用包PLOT3D格式火山」由 Karline Soetaert搜索。然後選擇最接近您的需求的地塊,並要求進行任何特定修改(如果有的話)。 –

+0

好材料。謝謝42-。 –

回答

1

您可以RGL surface3d嘗試策劃你z_matrix:

library(rgl) 

x <- 50*(1:nrow(z_matrix)) 
y <- 10*(1:ncol(z_matrix)) 

zlim <- range(z_matrix) 
zlen <- zlim[2] - zlim[1] + 1 

colorlut <- rainbow(zlen) # height color lookup table 

col <- colorlut[ z_matrix - zlim[1] + 1 ] # assign colors to heights for each point 

open3d() 
surface3d(x, y, z_matrix, color = col, back = "lines") 

enter image description here

隨着網格線(且不縮放X,Y軸):

x <- 1:nrow(z_matrix) 
y <- 1:ncol(z_matrix) 

zlim <- range(z_matrix) 
zlen <- zlim[2] - zlim[1] + 1 

colorlut <- terrain.colors(zlen) #rainbow(zlen) # height color lookup table 

col <- colorlut[ z_matrix - zlim[1] + 1 ] # assign colors to heights for each point 

open3d() 
persp3d(x, y, z_matrix, col = col) 
grid3d(c("x", "y+", "z")) 
surface3d(x, y, z_matrix, color = col, back = "lines") 

enter image description here

+0

請問您爲什麼需要將50和10乘以產生x和y向量?非常感謝。 –

+0

@郭顯彰只是爲了縮放/放大圖形的x和y維度(以便它看起來更好,我們可能不會縮放)。 –

+0

uodated代碼沒有縮放和添加網格線。 –

0

按照我自己的意見,並使用該火山的數據集,這是我認爲是你想要的圖像的最佳匹配儘可能的背景:與

libarary(plot3d) 
persp3D(z = volcano, col = "lightblue", shade = 0.5, 
ticktype = "detailed", bty = "b2") 

enter image description here

,這將是着色方案最適合在工作的例子中,但我想你可能想搜索「地形顏色」,如果你需要更精確的圖像:

png(); persp3D(z = volcano,clab = c(「height」,「m」), colkey = list(length = 0.5,shift = -0.1), ticktype =「detailed」,bty =「b2」); dev.off()

enter image description here

這包是使用基本圖形,所以你會希望通過閱讀?persp審查旋轉選項和?persp3D幫助頁面。這裏還有一個實驗:

png(); persp3D(z = volcano, col=terrain.colors(100), clab = c("height", "m"), xlab="PPM" , ylab="Col", zlab="Height", 
colkey=FALSE, theta=25, lighting="specular", 
ticktype = "detailed", bty = "b2"); dev.off() 

enter image description here