RGL包-多维数据集中的多维数据集 [英] rgl package - cube within a cube

查看:0
本文介绍了RGL包-多维数据集中的多维数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个立方体内的长方形棱镜。我需要立方体有1x1x1单位的尺寸,原点在0,0,0。理想情况下,立方体中的矩形应该从原点开始,然后从向量变量中拉出,以获得其XYZ维度。长方形棱镜只能有范围从0到1的正值,这就是为什么我只想显示正值,而不是似乎是cube3d的默认值,即在原点周围的所有维度上显示-1到1。

谁能给我指个正确的方向,告诉我如何使这件事起作用?

数据示例:

Augusta = c(0.4, 0.2, 0.8)

我当前拥有的代码(从stackoverflow中提取)-

c3d <- cube3d(color="red", alpha=0.5)  
c3d  
shade3d(c3d)  
axes3d()  
rgl.viewpoint(theta = 45, phi = 25, fov = 60, zoom = 1)  

我是否可以调整此功能以满足我的需要?如果是这样的话,这种方法会是什么样子?如果这不是正确的函数,您会建议什么?

我发现的另一种可能的方法是here

,但它需要不同的输入,因此不是首选方法

推荐答案

 #Data example 
 Nominal_City_Name = c(0.7,0.2,0.5)
 X = Nominal_City_Name[1]
 Y = Nominal_City_Name[2]
 Z = Nominal_City_Name[3]

 #Bring in RGL library
 library(rgl)

 #Contributor cuttlefish44's code
 c3d <- cube3d(color="grey", alpha=0.1)  
 c3d2 <- c3d %>% 
   translate3d(1, 1, 1) %>% 
   scale3d(0.5, 0.5, 0.5)

 c3d3 <- cube3d(color = "blue", alpha = (0.5)) %>% 
   translate3d(1, 1, 1) %>% 
   scale3d(0.5, 0.5, 0.5) %>% 
   scale3d(X, Z, Y)

 shade3d(c3d2)
 shade3d(c3d3)
 axes3d()
 # Add points at vertices
 points3d(t(c3d3$vb), size = 5)
 # Add lines to edges of box
 for (i in 1:6) lines3d(t(c3d3$vb)[c3d3$ib[,i],])

 #------------Add labels/title to 3d window-------
 # This version of title (commented out) doesn't work as well as the 
 # bgplot3d() version now included in output section below.  
 # Use this title3d() version if you want the title to be dynamic to 
 # the graphic.     

 #Title_XYZ = paste0(stakeholder," ","X, Y, Z")
 #title3d(main =Title_XYZ,cex = 2, line = 2)

 mtext3d("X Var",edge="x-+",line=2,las=2,cex=2,srt = 50,col = 
           "darkorange3")
 mtext3d("Y Var",edge="z+-",line=2.5,las=2,cex=2, col = 
           "chartreuse4", srt = 90)
 mtext3d("Z Var",edge="y-+",line=3,las=2,cex=2, col = 
           "darkblue")

 #
 #-------Create output file-------
 #This section first sets the window view parameters and window size 
 # to what I want it to be.  Then it exports to a location you choose.

 # After dynamically moving it to look the way you want in 3d view - 
 # Use par3d() to get view attributes (i.e., windowRect (window size) 
 # info), among other measurements.  Theta, phi, fov, and zoom give 
 # angles, field of vision, and zoom.

 rgl.viewpoint(theta = 45, phi = 4, fov = 60, zoom = 1)
 window_size = c(164,32,1259,1050)
 par3d(windowRect = window_size)

 #Adding title using a background plot.  This must be done AFTER 
 #resizing the window, because it doesn't scale gracefully.
 Title_XYZ = "This is your title"
 bgplot3d(
   plot.new() +
     title(main = Title_XYZ, line = -10,cex.main=3))

        #a = folder, b = stakeholder name, c = file extension, d = concat      of 
   #all 3 for export
   # a = "C:\Users\MyUserName\Documents\R\export"
   # b = Title_XYZ
   # c=".jpg"
   # d = paste0(a,b,c)
   # rgl.snapshot(d)

这篇关于RGL包-多维数据集中的多维数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆