2016-08-16 45 views
0

我對R很感興趣,也更喜歡用它來繪圖。如何使用三維圖形顯示R中的3列數據?

我在數據框中有這個示例數據。

head(dframe) 
    maingroup subgroup n 
1  BR  A 315 
2  MV  A 394 
3  SAN  A 253 
4  BR  B 230 
5  MV  B 242 
6  SAN  B 152 

現在我想它想象:在Z軸

  • maingroup
  • 亞組在x軸
  • N於y軸

快速和骯髒的例子。 enter image description here

回答

3

如果這是出版(靜態圖像),你可以使用scatterplot3d

library(scatterplot3d) 
DT <- data.frame(maingroup = letters[1:6], subgroup = letters[26:21], n = 1:6) 
scatterplot3d(x = DT$maingroup, # x axis 
       y = DT$subgroup, # y axis 
       z = DT$n,   # z axis 
       x.ticklabs = levels(DT$maingroup), 
       y.ticklabs = levels(DT$subgroup)) 

enter image description here

對於一些更具互動性,你可以使用plotly

library(plotly) 

plot_ly(x = DT$maingroup, # x axis 
     y = DT$subgroup, # y axis 
     z = DT$n,   # z axis 
     type = "scatter3d") 

enter image description here

+0

這太棒了。這個答案是我的簡單問題。但是現在一些詳細的問題已經出現。我會在這裏開一個新的。 – buhtz

+0

[如何在R中的三維散點圖中獲得正確的ticklabs](http://stackoverflow.com/questions/38989793/how-to-get-correct-ticklabs-in-a-3d-scatterplot-in-r )和[如何在R中繪製多個二維圖?](http://stackoverflow.com/questions/38990001/how-to-draw-multiple-2d-plots-in-a-3d-情節在-R) – buhtz

相關問題