有吸引力的3D绘图在研发 [英] Attractive 3D plot in R
问题描述
我写一个提案,并需要一个3D图是这样的:
I am writing a proposal and need a 3D plot something like this:
但preferably更具吸引力。我需要每个点的尺寸,以反映该物种的丰度和通过连接点而构成的体积的概要
but preferably more attractive. I need the size of each point to reflect the abundance of the species and an outline of the volume created by connecting the points.
样本数据:
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
如何使这样的图更具吸引力的任何建议(可能包括网格线?我不想在轴上任何数字不过)
Any suggestion on how to make such a graph more attractive (perhaps including gridlines? I do not want any numbers on the axes however)
我打周围的 scatterplot3d
,但它并不绘制所有我的观点,我个人认为该立方体有一种异样的目光吧...喜欢它是不是很准确......
I have played around with scatterplot3d
, but it doesn't plot all my points and I personally find that the cube has a strange look to it... like it is not quite accurate...
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))
推荐答案
这应该让你开始使用包 RGL
。注:在重看我看我使用你的XYZ COORDS比你做的有点不同,但概念是相同的。
This should get you started using package rgl
. Note: On re-read I see I am using your xyz coords a little different than you did, but the concept is the same.
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将改进图)。
Now you can rotate your diagram interactively and then use rgl.snapshot
to get a hardcopy (using antialias arguments in spheres3d will improve the diagram).
这篇关于有吸引力的3D绘图在研发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!