unity3d 可視化編程_R編程系列:R中的3D可視化

unity3d 可視化編程

In the last blog, we have learned how to create Dynamic Maps Using ggplot2. In this article, we will explore more into the 3D visualization in R programming language by using the plot3d package.

在上一個博客中,我們學習了如何創建 使用ggplot2使用動態地圖 。 在本文中,我們將使用plot3d包對R編程語言中的3D可視化進行更多探索

The plot3d package can be used to generate stunning 3-D plots in R. It can generate an interesting array of plots, but in this recipe, we will focus on creating 3-D scatterplots. These arise in situations where we have three variables, and we want to plot the triplets of values on the xyz space.

plot3d包可用于在R中生成令人驚嘆的3-D圖。它可以生成有趣的圖陣列,但是在本食譜中,我們將重點介紹創建3-D散點圖。 這些出現在我們有三個變量的情況下,我們想在xyz空間上繪制三元組值。

We will use a specific dataset to plot them into fancy plots using the plot3d package. The following steps are implemented to create 3D visualization in R.

我們將使用plot3d包使用特定的數據集將它們繪制成精美的圖。 執行以下步驟以在R中創建3D可視化 。

Step 1: Install the required packages which are needed for 3D visualization in R.

步驟1:在R中安裝3D可視化所需的必需軟件包。

> install.packages("rgl")
Installing package into ‘C:/Users/admin/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.6/rgl_0.100.30.zip'
Content type 'application/zip' length 4253430 bytes (4.1 MB)
downloaded 4.1 MB

package ‘rgl’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\admin\AppData\Local\Temp\Rtmpymt5Jd\downloaded_packages
> install.packages("plot3D")
Installing package into ‘C:/Users/admin/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
package ‘plot3D’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\admin\AppData\Local\Temp\Rtmpymt5Jd\downloaded_packages

Include the required libraries in the mentioned workspace.

在上述工作區中包括所需的庫。

> library(plot3D)
> library(rgl)

Step 2: We will use the dataset named “income.csv” which includes all the necessary parameters which are needed for understanding income rates of every employee.

步驟2:我們將使用名為“ income.csv ”的數據集,其中包括了解每個員工的收入率所需的所有必要參數。

Image for post

Step 3: Analyze the data structure of the dataset with the mentioned attributes.

步驟3:使用上述屬性分析數據集的數據結構。

> str(income)
'data.frame': 30 obs. of 5 variables:
$ names : Factor w/ 30 levels "brady","brandy",..: 27 29 14 17 10 26 22 24 30 18 ...
$ Education: num 21.6 18.3 12.1 17 19.9 ...
$ Seniority: num 113 119 101 188 20 ...
$ Income : num 99.9 92.6 34.7 78.7 68 ...
$ gender : int 1 1 0 0 1 1 1 1 1 1 ...

Step 4: It is important to understand the five-point summary of data before proceeding further. Visualization requires a lookout on bivariate and univariate analysis which is clearly understood with a five-point summary of data.

步驟4:在繼續進行之前,了解數據的五點摘要很重要。 可視化需要監視雙變量和單變量分析,并通過五點數據摘要清楚地了解。

> summary(income)
names Education Seniority Income
brady : 1 Min. :10.00 Min. : 20.00 Min. :17.61
brandy : 1 1st Qu.:12.48 1st Qu.: 44.83 1st Qu.:36.39
brian : 1 Median :17.03 Median : 94.48 Median :70.80
brittany: 1 Mean :16.39 Mean : 93.86 Mean :62.74
bruce : 1 3rd Qu.:19.93 3rd Qu.:133.28 3rd Qu.:85.93
charles : 1 Max. :21.59 Max. :187.59 Max. :99.92
(Other) :24
gender
Min. :0.0000
1st Qu.:0.0000
Median :1.0000
Mean :0.6333
3rd Qu.:1.0000
Max. :1.0000

Step 5: Let us with bivariate analysis which focusses on 2-dimensional data and scatter plot is considered as an easy method to create the same.

步驟5:讓我們進行專注于二維數據的雙變量分析,而將散點圖視為創建該變量的簡便方法。

> scatter3D(x = inc$Education, y = inc$Income, z =inc$Seniority,
+ colvar = inc$Income,
+ pch = 16, cex = 1.5, xlab = "Education", ylab = "Income",
+ zlab = "Seniority", theta = 60, d = 2,clab = c("Income"),
+ colkey = list(length = 0.5, width = 0.5, cex.clab = 0.75,
+ dist = -.08, side.clab = 3)
+ ,main = "Relationship Between Income , Education and Seniority")

Here, we are plotting “Education” in the x-axis, “Income” in the y-axis and the “Seniority” level in the z-axis. The distinct legends are created based on the range of income parameters. The plot is helpful to show the relationship between Income, Education, and Society.

在這里,我們在x軸上繪制“教育”,在y軸上繪制“收入”,在z軸上繪制“高級”水平。 根據收入參數范圍創建不同的圖例。 該圖有助于顯示收入,教育和社會之間的關系。

Image for post

We can add more effects to the mentioned 3D plot with plane surfaces and ranges depicted in a specific order. Consider that we want to implement a linear regression model to establish the relationship between Seniority, Education and Income we can create a predictive model for the same.

我們可以使用特定順序描繪的平面和范圍為上述3D圖添加更多效果。 考慮到我們要實現線性回歸模型以建立資歷,教育和收入之間的關系,我們可以為此創建一個預測模型。

Step 6: Create a predictive model with the help of the RGL package. RGL is the 3D real-time rendering package in the R programming language. It provides high-level functions to create an interactive graph. To create a 3D plot of linear regression, we need to create a predictive model of the same.

步驟6:借助RGL軟件包創建預測模型。 RGL是R編程語言中的3D實時渲染包。 它提供了高級功能來創建交互式圖形。 要創建線性回歸的3D圖,我們需要創建相同的預測模型。

> lmin = lm(inc$Income~inc$Education+inc$Seniority)
> lmin

Call:
lm(formula = inc$Income ~ inc$Education + inc$Seniority)

Coefficients:
(Intercept) inc$Education inc$Seniority
-50.0856 5.8956 0.1729
> est = coef(lmin)
> a = est["inc$Education"]
> b = est["inc$Seniority"]
> c=-1
> d= est["(Intercept)"]
> est
(Intercept) inc$Education inc$Seniority
-50.0856387 5.8955560 0.1728555
> a
inc$Education
5.895556
> b
inc$Seniority
0.1728555
> c
[1] -1
> d
(Intercept)
-50.08564

Step 7: Once the required parameters for linear regression are taken into consideration, we can create an interactive graph where we plot the data points as a scattered graph and later embed the linear regression model in them.

步驟7:一旦考慮了線性回歸所需的參數,我們就可以創建一個交互式圖形,在其中將數據點繪制為散點圖,然后將線性回歸模型嵌入其中。

> plot3d(inc$Education,inc$Seniority,inc$Income, type = "s",
+ col = "blue", xlab = "Education",ylab = "Income",zlab =
+ "Seniority",box = FALSE)
Image for post

Now we will embed the linear regression line as mentioned below:

現在,我們將嵌入線性回歸線,如下所示:

planes3d(a,b,c,d, alpha = 0.5, col = "red")
Image for post

Step 8: We can create a surface plot that defines the volume and intensity of the data. Following steps are implemented to create a specific plot as mentioned below:

步驟8:我們可以創建一個表面圖來定義數據的數量和強度。 執行以下步驟來創建特定圖,如下所述:

> inc= read.csv("income2.csv")
> View(inc)
> row.names(inc)= inc$names
> inc
names Education Seniority Income gender
tim tim 21.58621 113.10345 99.91717 1
tom tom 18.27586 119.31034 92.57913 1
kim kim 12.06897 100.68966 34.67873 0
mary mary 17.03448 187.58621 78.70281 0
hary hary 19.93103 20.00000 68.00992 1
thomas thomas 18.27586 26.20690 71.50449 1
peter peter 19.93103 150.34483 87.97047 1
romeo romeo 21.17241 82.06897 79.81103 1
wald wald 20.34483 88.27586 90.00633 1
matt matt 10.00000 113.10345 45.65553 1
pam pam 13.72414 51.03448 31.91381 0
pamela pamela 18.68966 144.13793 96.28300 0
larry larry 11.65517 20.00000 27.98250 1
karl karl 16.62069 94.48276 66.60179 1
brian brian 10.00000 187.58621 41.53199 1
dan dan 20.34483 94.48276 89.00070 1
sim sim 14.13793 20.00000 28.81630 0
kristin kristin 16.62069 44.82759 57.68169 0
chiu chiu 16.62069 175.17241 70.10510 1
bruce bruce 20.34483 187.58621 98.83401 1
brady brady 18.27586 100.68966 74.70470 1
brandy brandy 14.55172 137.93103 53.53211 0
charles charles 17.44828 94.48276 72.07892 1
timothy timothy 10.41379 32.41379 18.57067 0
jerry jerry 21.58621 20.00000 78.80578 1
garry garry 11.24138 44.82759 21.38856 1
jena jena 19.93103 168.96552 90.81404 0
ram ram 11.65517 57.24138 22.63616 1
brittany brittany 12.06897 32.41379 17.61359 0
milly milly 17.03448 106.89655 74.61096 0

Here, we convert the dataset into a separate vector and we also created the index based on the names of candidates. Text3d is the function that adds text to the plane surface. The text represents actual data representation. As we converted the row names with names of candidates, it becomes easy to display text in the 3D plot.

在這里,我們將數據集轉換為單獨的向量,并且還基于候選名稱創建了索引。 Text3d是將文本添加到平面的功能。 文本表示實際數據表示。 當我們用候選名稱轉換行名稱時,在3D圖中顯示文本變得很容易。

> text3D(x = inc$Education, y = inc$Income, z =inc$Seniority,
+ colvar = inc$Income,labels= row.names(inc),
+ pch = 16, cex = 0.8, xlab = "Education", ylab = "Income",
+ zlab = "Seniority", theta = 60, d = 2,clab = c("Income"),
+ colkey = list(length = 0.5, width = 0.5, cex.clab = 0.75,
+ dist = -.08, side.clab = 3)
+ ,bty = "g")
Image for post

Step 9: We can convert the values in proper labels with distinct colors. This helps to visualize the 3D plot more easily and distinctly with a specific color range.

步驟9:我們可以將值轉換為具有不同顏色的適當標簽。 這有助于在特定顏色范圍內更輕松,更清晰地可視化3D圖。

> text3D(x = inc$Education, y = inc$Income, z =inc$Seniority,
+ colvar= inc$gender,col = c("red","black"),labels= row.names(inc),
+ pch = 16, cex = 0.8,xlab = "Education", ylab = "Income",
+ zlab = "Seniority", theta = 60, d = 2,clab = c("Income"),
+ bty = "g", colkey = FALSE)
> legend("topright", fill = c("red", "black"), legend=
+ c("Female","Male"), bty = "n")

等高線圖 (Contour Plots)

Contour plots visually represent the intensity of the plot. The color and graphical representation help in the visual analysis of data.

等高線圖直觀地表示了該圖的強度。 顏色和圖形表示有助于數據的可視化分析。

> x = y = seq(-3,3, length.out = 10)
> x
[1] -3.0000000 -2.3333333 -1.6666667 -1.0000000 -0.3333333 0.3333333
[7] 1.0000000 1.6666667 2.3333333 3.0000000
> y
[1] -3.0000000 -2.3333333 -1.6666667 -1.0000000 -0.3333333 0.3333333
[7] 1.0000000 1.6666667 2.3333333 3.0000000
> f = function(x,y){ z= (y^2-x^2)}
> m = outer(x,y,f)
>
> image2D(m)
> image2D(m, contour = TRUE)
>
> persp3D(z = m, contour = TRUE)
> persp3D(z = volcano, contour = TRUE)
>
> library(rgl)
> c = terrain.colors(5)
> persp3d(z = volcano, contour = TRUE, col = c)

The output of the contour plot is mentioned below:

等高線圖的輸出如下所述:

Image for post

The interactive 3d plot is mentioned below:

交互式3d圖如下所示:

Image for post

We can also create a plot with an animation feature which increases the interactive rate. For this, it is important to install an “animation” package which helps in creating the plots as desired.

我們還可以創建帶有動畫功能的繪圖,以提高交互速率。 為此,重要的是安裝一個“動畫”程序包,該程序包可以幫助創建所需的繪圖。

> install.packages("plotrix")
Installing package into ‘C:/Users/admin/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.6/plotrix_3.7-7.zip'
Content type 'application/zip' length 1132324 bytes (1.1 MB)
downloaded 1.1 MB

package ‘plotrix’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\admin\AppData\Local\Temp\RtmpSCUS7b\downloaded_packages
>
> install.packages("animation")
Installing package into ‘C:/Users/admin/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.6/animation_2.6.zip'
Content type 'application/zip' length 548202 bytes (535 KB)
downloaded 535 KB

package ‘animation’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\admin\AppData\Local\Temp\RtmpSCUS7b\downloaded_packages
>
> library(plot3D)
> library(plotrix)

Attaching package: ‘plotrix’

The following object is masked from ‘package:rgl’:

mtext3d

> library(animation)
>
> x = y = seq(0,2*pi, length.out = 100)
>
> z = mesh(x,y)
> u = z$x
> v = z$y
>
> m= (sin(u)*sin(2*v)/2)
> n = (sin(2*u)*cos(v)*cos(v))
> o = (cos(2*u)*cos(v)*cos(v))
>
> surf3D(m, n,o, colvar = o, border = "black",colkey = FALSE,box = TRUE)
>
> surf3D(m, n,o, colvar = o, border = "black",colkey = TRUE, box = TRUE,theta = 60)
>
> surf3D(m, n,o, colvar = o, border = "black",colkey = TRUE,box = TRUE,theta = 100)
>
> library("animation")
> saveHTML({
+ for (i in 1:100 ){
+ x = y = seq(0,2*pi, length.out = 100)
+ z = mesh(x,y)
+ u = z$x
+ v = z$y
+ m= (sin(u)*sin(2*v)/2)
+ n = (sin(2*u)*cos(v)*cos(v))
+ o = (cos(2*u)*cos(v)*cos(v))
+ surf3D(m, n,o, colvar = o, border = "black",colkey = FALSE,
+ theta = i, box = TRUE)
+ }
+ },interval = 0.1, ani.width = 500, ani.height = 1000)

The ranges of the graphs are depicted below:

圖的范圍如下所示:

Image for post
Image for post

The file is saved with .html extension and represents the graphical animation of the values in three co-ordinates.

該文件以.html擴展名保存,并以三個坐標表示值的圖形動畫。

So, this was all about 3D visualization in R programming!

因此,這一切都與R編程中的3D可視化有關!

In the next section, we will be going to learn about Data Wrangling and Visualization in R programming language.

在下一節中,我們將學習R編程語言中的數據整理和可視化

Originally published https://blog.eduonix.com on March 27, 2020

最初 2020 3月27日發布 https://blog.eduonix.com

翻譯自: https://medium.com/eduonix/r-programming-series-3d-visualization-in-r-3f9280d7ddb4

unity3d 可視化編程

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388572.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388572.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388572.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

linux無法設置變量,linux – crontab在作業之前無法設置變量

我的crontab看起來像:rootslack13x64:~# crontab -l -u dnd# some variablesSHELL/bin/bashPATH/bin:/usr/bin:/usr/local/bin:/home/dnd/binMAILTOroot# Actual jobs40 20 * * * /home/dnd/cron_jobs/some_job.sh55 23 * * Fri /home/dnd/cron_jobs/other_job.py作…

詳談P(查準率),R(查全率),F1值

怎么來的? 我們平時用的精度accuracy,也就是整體的正確率 acc predict_right_num / predict_num 這個雖然常用,但不能滿足所有任務的需求。比如,因為香蕉太多了,也不能撥開人工的一個一個的看它的好壞(我愛吃啊&#…

網站系統分布式架構

寫這篇文章之前,需要有些論點和論據,以表明網絡系統在極端情況下的情況,先來看看世界上排名靠前的網站。 1、 FaceBook 2、 Google 從這兩個站可以看出,當下比較極限的日均訪問量在2~3億,PV值…

linux文件系統學習,linux文件系統之tmpfs學習

關于文件系統,我們在下面的博文中已有做簡單的介紹,外鏈網址已屏蔽本篇博文我們學習的是文件系統中的tmpfs。tmpfs是一種偽文件系統,它是從DRAM中創建出來的,相比于磁盤而言,其具有更高的訪問效率。如何創建一個tmpfs&…

python 數據科學 包_什么時候應該使用哪個Python數據科學軟件包?

python 數據科學 包Python is the most popular language for data science. Unfortunately, it can be tricky to know which of the many data science libraries to use when. ??Python是數據科學中最流行的語言。 不幸的是,要知道何時使用許多數據科學庫中的哪…

Go語言開發環境配置

http://blog.csdn.net/hil2000/article/details/41261267/ 一.我為什么要學習go語言 當今已經是移動和云計算時代,Go出現在了工業向云計算轉型的時刻,簡單、高效、內 置并發原語和現代的標準庫讓Go語言尤其適合云端軟件開發(畢竟它就是為此而…

微軟研發致勝策略

第一章奠定基礎 1.千萬不要把程序設計師的時間浪費在改善產品以外的工作上。 2.保護程序設計師不受任何阻礙和干擾。 3.永遠記得自己真正的目標,然后讓團隊用最有將效又最愉快的方法把它完成。 4.理清詳細的項目目…

熊貓tv新功能介紹_您應該知道的4種熊貓繪圖功能

熊貓tv新功能介紹Pandas is a powerful package for data scientists. There are many reasons we use Pandas, e.g. Data wrangling, Data cleaning, and Data manipulation. Although, there is a method that rarely talks about regarding Pandas package and that is the …

CPP_封裝_繼承_多態

類的三方法:封裝,繼承,多態。封裝:使用一整套方法去創建一個新的類型,這叫類的封裝。繼承:從一個現有的類型基礎上,稍作改動,得到一個新的類型的方法,叫類的繼承。多態&a…

win與linux淵源,微軟與Linux從對立走向合作,WSL是如何誕生的

原標題:微軟與Linux從對立走向合作,WSL是如何誕生的正文Windows Subsystem for Linux(WSL)的開發,讓微軟從Linux的對立面走向合作,并且不斷加大對開源社區的支持力度。而作為微軟歷史上的重要轉折點,外界對WSL技術在Pr…

文件編輯器 vi

1、關于文本編輯器; 文本編輯器有很多,比如圖形模式的gedit、kwrite、OpenOffice ... ... ,文本模式下的編輯器有vi、vim(vi的增強版本)和nano ... ... vi和vim是我們在Linux中最常用的編輯器。我們有必要介紹一下vi&a…

MFC80.DLL復制到程序目錄中,也有的說復制到安裝目錄中

在用VS2005學習C調試程序的時候,按F5鍵,總提示這個問題, 不曉得什么原因,網上有的說找到MFC80.DLL復制到程序目錄中,也有的說復制到安裝目錄中,可結果很失望,也有的VS2005安裝有問題&#xff0…

vs顯示堆棧數據分析_什么是“數據分析堆棧”?

vs顯示堆棧數據分析A poor craftsman blames his tools. But if all you have is a hammer, everything looks like a nail.一個可憐的工匠責怪他的工具。 但是,如果您只有一把錘子,那么一切看起來都像釘子。 It’s common for web developers or databa…

服務器

服務器主流品牌:華為、浪潮、戴爾、惠普華為服務器:華為FusionServer RH2288 V3 華為FusionServer RH5885 V3 浪潮服務器: 浪潮英信NP3020M4 浪潮英信NF5280M4 戴爾服務器: 戴爾PowerEdge R730 機架式服務器 戴爾PowerEdge R740 機…

樹莓派 zero linux,樹莓派 zero基本調試

回家之前就從網上購買了一堆設備,回去也不能閑著,可以利用家里相對齊全的準備安裝調試。結果人還沒回來,東西先到了。購買的核心裝備是樹莓派zero w,雖然已經知道它比家族大哥樹莓派小不少,但拿到手里還是驚奇它的小巧…

error C2440 “static_cast” 無法從“void (__thiscall CPppView )(void)”轉換為“LRESULT (__thiscall

error C2440 “static_cast” 無法從“void (__thiscall CPppView )(void)”轉換為“LRESULT (__thiscall CWnd )(WPARAM,LPARAM)” 不能轉換void (_thiscall CMainFrame::*)(void)to LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)開發平臺由VC6.0升級至VS2005,需要…

簡單的編譯流程

簡易編譯器流程圖: 一個典型的編譯器,可以包含為一個前端,一個后端。前端接收源程序產生一個中間表示,后端接收中間表示繼續生成一個目標程序。所以,前端處理的是跟源語言有關的屬性,后端處理跟目標機器有關的屬性。 復…

廣告投手_測量投手隱藏自己的音高的程度

廣告投手As the baseball community has recently seen with the Astros 2017 cheating scandal, knowing what pitch is being thrown gives batters a game-breaking advantage. However, unless you have an intricate system of cameras and trash cans set up, knowing wh…

linux事務隔離級別,事務的隔離級別(Transaction isolation levels)2

READ COMMITTEDREAD COMMITTED這是數據庫默認的隔離級別。它能保證你不能讀取那張表格數據,只要有其它事務還在改變這張表格數據。可是,因為sql server在select操作的時,鎖表格時間就那么一小會兒,如果一個事務在READ COMMITTED級…

Asp導出到Excel之二

response.contentType "application/vnd.ms-excel" response.addheader "Content-Disposition", "attachment; filename引出文件.xls" 一、適用于動態和表態表。 二、頁面最好只存放數據表,不要有其它內容。 三、對于分頁的情…