简体   繁体   English

如何使用3维图可视化R中的3列数据?

[英]How do I visualize 3 column data in R with a 3-dimensional plot?

I am quite new to R and more to plotting with it. 我对R很陌生,并且对使用R绘图更感兴趣。

I have this example data in a dataframe. 我在数据框中有这个示例数据。

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

Now I want to visualize it: 现在我想形象化它:

  • maingroup on the z-axis z轴上的主群
  • subgroup on the x-axis x轴上的子组
  • n on the y-axis y轴上的n

Quick and dirty example. 快速而肮脏的例子。 在此处输入图片说明

If this is for publication (static image), you can use scatterplot3d : 如果这是用于发布(静态图像),则可以使用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))

在此处输入图片说明

For something more interactive, you can use plotly : 对于更具交互性的内容,可以使用plotly

library(plotly)

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM