r - R 中有吸引力的 3D 绘图

标签 r graphics 3d plot gridlines

我正在写一个提案,需要一个像这样的 3D 绘图:

enter image description here

但最好更具吸引力。我需要每个点的大小来反射(reflect)物种的丰富度以及通过连接点创建的体积轮廓。

示例数据:

input<-data.frame(
label=c("sp1","sp2","sp3","sp4"),
trait_x=c(6,6,6,1),
trait_y=c(7,7,7,1),
trait_z=c(8,8,8,1),
point_size=c(6,7,8,1)
)
input
  label trait_x trait_y trait_z point_size
1   sp1       6       7       8        6
2   sp2       6       7       8        7
3   sp3       6       7       8        8
4   sp4       1       1       1        1

关于如何使这样的图表更具吸引力的任何建议(也许包括网格线?但是我不希望轴上有任何数字)

我玩过scatterplot3d,但它并没有绘制出我所有的点,而且我个人发现立方体的外观很奇怪......就像它不太准确一样...... .

library(scatterplot3d)
x<-input$trait_x
y<-input$trait_y
z<-input$trait_z
scatterplot3d(x,y,z,xlim=c(0,10),ylim=c(0,10),zlim=c(0,10))

enter image description here

最佳答案

这应该可以帮助您开始使用包rgl。注意:重新阅读时,我发现我使用的 xyz 坐标与您使用的略有不同,但概念是相同的。

input<-data.frame( # I adjusted the values for better appearance in demo
label=c("sp1","sp2","sp3","sp4"),
trait_x=c(6,7,11,1),
trait_y=c(10,7,9,1),
trait_z=c(4,7,6,1),
point_size=c(6,7,8,1)
)
names(input) <- c("name", "x", "y", "z", "radius")
input$radius <- input$radius*0.2

require("rgl")

spheres3d(input[,2:4], radius = input[,5], col = c("red", "green", "blue", "orange"), alpha = 0.5)
axes3d(box = TRUE)
title3d(xlab = "x_trait", ylab = "y_trait", zlab = "z_trait")
text3d(input[1,2:4], texts = "species X")
# next line is clunky but you can do it more elegantly
segs <- rbind(input[1:2,2:4], input[2:3,2:4], input[3:4,2:4], input[c(4,1),2:4])
segments3d(segs)

现在,您可以交互地旋转图表,然后使用 rgl.snapshot 获取硬拷贝(在 spheres3d 中使用抗锯齿参数将改进图表)。

enter image description here

关于r - R 中有吸引力的 3D 绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16130025/

相关文章:

c# - 如何为面板设置双缓冲?

3d - 计算两个 3D 三角形是否在同一平面上

r - 使用 rvest 抓取图像标题

optimization - 超越 R 的优化功能

r - 使用字符串中的列名初始化 R data.table

r - 如何将字符串中的括号提取到新列中

.net - 绘图.图形,性能不佳

graphics - R图形的命名点

javascript - 使用 Tween 绕世界轴精确旋转

c++ - 使用顶点缓冲对象渲染不同的三角形类型和三角形扇形? (OpenGL)