r語言繪制雷達圖_用r繪制雷達蜘蛛圖

r語言繪制雷達圖

I’ve tried several different types of NBA analytical articles within my readership who are a group of true fans of basketball. I found that the most popular articles are not those with state-of-the-art machine learning technologies, but those with straightforward and meaningful graphs.

我在讀者群中嘗試了幾種不同類型的NBA分析文章,這些文章是一群真正的籃球迷。 我發現最受歡迎的文章不是那些具有最新的機器學習技術的文章,而是那些具有簡單明了的圖表的文章。

At a certain stage of my career as a data scientist, I realized that delivering the information is more important than showing the fancy models. Perhaps that’s why linear regression is still one of the most popular models in the finance world.

在我作為數據科學家的職業生涯的某個階段,我意識到提供信息比展示精美的模型更為重要。 也許這就是為什么線性回歸仍然是金融界最受歡迎的模型之一的原因。

In this post, I am going to talk about a simple topic. It is how to draw the spider plot, or the radar plot, which is one of the most essential graphs in a comparative analysis. I am implementing the code in R.

在這篇文章中,我將討論一個簡單的話題。 這是繪制蜘蛛圖或雷達圖的方法 ,它是比較分析中最重要的圖之一。 我正在R中實現代碼。

數據 (Data)

NBA players’ basic statistics and advanced statistics per game in 2019–2020 NBA playoffs. (from basketball reference)

在2019–2020 NBA季后賽中,NBA球員的每場比賽的基本統計數據和高級統計數據。 ( 參考籃球 )

(Code)

Let’s first visualize James Harden’s stats in a spider plot. We only focus on five stats: PTS (points), TRB (total rebounds), AST (assists), STL (steals), and BLK (blocks).

讓我們首先在蜘蛛圖中形象化詹姆斯·哈登的統計數據。 我們僅關注五項統計數據:PTS(得分),TRB(總籃板),AST(助攻),STL(搶斷)和BLK(蓋帽)。

df = read.csv("playoff_stats.csv")
maxxx = apply(df[,c("PTS.","TRB","AST","STL","BLK")],2,max)
minnn = apply(df[,c("PTS.","TRB","AST","STL","BLK")],2,min)

In the code of this block, the data was read to a data frame, “df”. And the maximum and minimum values of each column were calculated because these values are useful to define the boundary of the data in the spider plot.

在該塊的代碼中,數據被讀取到數據幀“ df”。 并計算每列的最大值和最小值,因為這些值可用于定義蜘蛛圖中數據的邊界。

For example, I extracted the stats of James Harden and LeBron James for our analysis.

例如,我提取了James Harden和LeBron James的統計數據進行分析。

df_sel = df[c(3,10),c("PTS.","TRB","AST","STL","BLK")]
rownames(df_sel) = c("Harden","Lebron")

To define the function of the spider plot, we need to load the fmsb package.

要定義蜘蛛圖的功能,我們需要加載fmsb包。

comp_plot = function(data,maxxx,minnn){
library(fmsb)
data = rbind(maxxx, minnn, data)
colors_border=c( rgb(0.2,0.5,0.5,0.9), rgb(0.8,0.2,0.5,0.9) , rgb(0.7,0.5,0.1,0.9) )
colors_in=c( rgb(0.2,0.5,0.5,0.4), rgb(0.8,0.2,0.5,0.4) , rgb(0.7,0.5,0.1,0.4) )
radarchart( data, axistype=1 , pcol=colors_border , pfcol=colors_in , plwd=4 , plty=1, cglcol="grey", cglty=1, axislabcol="grey", caxislabels=rep("",5), cglwd=0.8, vlcex=0.8)
legend(x=0.5, y=1.2, legend = rownames(data[-c(1,2),]), bty = "n", pch=20 , col=colors_in , text.col = "black", cex=1, pt.cex=3)
}

In the function, “radarchart” is to draw the spider plot, some arguments of which is explained below.

在函數中,“ radarchart”用于繪制蜘蛛圖,下面將解釋其中的一些參數。

pcol and pfcol define the color of lines and the color to fill, respectively. plwd and plty give the line width and type of the spider plot, respectively. The grid line (or the web) has the color and type defined by cglcol and cglty. I don’t want to put any label in the center of the spider plot, so the caxislabels is given null strings (rep(“”,5)).

pcolpfcol分別定義線條的顏色和要填充的顏色。 plwdplty分別給出了蜘蛛圖的線寬和類型。 網格線(或網絡)的顏色和類型由cglcolcglty定義。 我不想在蜘蛛圖的中心放置任何標簽,因此caxislabels給出了空字符串(rep(“”,5))。

Let’s see how Harden’s stats look.

讓我們看看哈登的統計數據如何。

comp_plot(df_sel[1,],maxxx,minnn)
Image for post
Spider plot of James Harden’s playoff stats
詹姆斯·哈登季后賽數據的蜘蛛情節

From the plot above, we can see that Harden is not only an excellent scorer (high points) but also a playmaker (high assists). These interpretations are perfectly consistent with the James Harden we know.

從上圖可以看出,哈登不僅是出色的得分手(高分),而且是組織者(高助攻)。 這些解釋與我們所知的詹姆斯·哈登完全吻合。

To compare the stats between James Harden and LeBron James, let’s input both players’ stats to the function.

為了比較詹姆斯·哈登和勒布朗·詹姆斯之間的數據,我們將兩個球員的數據輸入到該函數中。

comp_plot(df_sel,maxxx,minnn)
Image for post
Spider plot of comparison between James Harden and LeBron James
詹姆斯·哈登與勒布朗·詹姆斯之間的比較蜘蛛圖

We can see that LeBron has got better rebound and assist numbers in the stats comparing to Harden even though his scoring is not as good as Harden.

我們可以看到,勒布朗的得分和助攻數據都比哈登更好,盡管他的得分不如哈登。

Pretty straight forward, right?

很簡單吧?

Let’s do a similar comparison between Giannis Antetokounmpo and Kawhi Leonard in their advanced statistics, which include offense box plus/minus (OBPM), defense box plus/minus (DBPM), offense win share (OWS), defense win share (DWS), and true shooting percentage (TS).

讓我們在Giannis Antetokounmpo和Kawhi Leonard的高級統計數據中進行類似的比較,其中包括進攻框正負(OBPM),防守框正負(DBPM),進攻贏率(OWS),防守贏率(DWS),和真實拍攝百分比(TS)。

df = read.csv("playoff_stats_adv.csv")
maxxx = apply(df[,c("OBPM","DBPM","OWS","DWS","TS.")],2,max)
minnn = apply(df[,c("OBPM","DBPM","OWS","DWS","TS.")],2,min)
df_sel = df[c(1,3),c("OBPM","DBPM","OWS","DWS","TS.")]
rownames(df_sel) = c("Giannis","Kawhi")

Let’s see Giannis’s stats first.

首先讓我們看看吉安尼斯的統計數據。

comp_plot(df_sel[1,],maxxx,minnn)
Image for post
Spider plot of Giannis Antetokounmpo’s playoff advanced stats
Giannis Antetokounmpo的季后賽高級數據

We can find that Giannis is an all-round star because he has good stats in almost every aspect. No wonder he won his second MVP for the 2019–2020 regular season.

我們可以發現吉安尼斯是全能明星,因為他幾乎在各個方面都有出色的數據。 難怪他贏得了2019–2020常規賽第二次MVP。

Next, let’s compare Giannis with Kawhi Leonard in their advanced statistics.

接下來,讓我們將Giannis和Kawhi Leonard的高級統計數據進行比較。

comp_plot(df_sel,maxxx,minnn)
Image for post
Spider plot of comparison between Giannis Antetokounmpo and Kawhi Leonard
Giannis Antetokounmpo和Kawhi Leonard之間的比較蜘蛛圖

We can see that Giannis outperformed Kawhi in all aspects of the advanced stats.

我們可以看到,吉安尼斯在所有高級統計數據方面都勝過了Kawhi。

You can compare any number of players with this simple function, however, I don’t recommend to use a spider plot for the comparison of more than 3 individuals.

您可以使用此簡單功能比較任意數量的玩家,但是,我不建議使用蜘蛛圖來比較3個以上的玩家。

If you do need to compare a large group of objects, a heatmap could be a better choice for visualization. Here is one of my previous posts of the best heatmap function in R.

如果確實需要比較大量對象,則熱圖可能是可視化的更好選擇。 這是我以前有關R中最佳熱圖函數的文章之一。

I hope this short article could contribute to your toolkit as a data scientist!

我希望這篇簡短的文章可以對您作為數據科學家的工具包有所幫助!

Image for post
Photo by Zan on Unsplash
Zan在Unsplash上的照片

翻譯自: https://towardsdatascience.com/draw-a-radar-spider-plot-with-r-4af9693c3237

r語言繪制雷達圖

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

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

相關文章

java 分裂數字_分裂的補充:超越數字,打印物理可視化

java 分裂數字As noted in my earlier Nightingale writings, color harmony is the process of choosing colors on a Color Wheel that work well together in the composition of an image. Today, I will step further into color theory by discussing the Split Compleme…

Java 集合 之 Vector

http://www.verejava.com/?id17159974203844 import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.Vector;public class Test {/*** param args the command line arguments*/public static void main(String[] args) {//打印…

前端電子書單大分享~~~

前言 純福利, 如果你不想買很多書,只想省錢看電子書; 如果你找不到很多想看書籍的電子書版本; 那么,請保存或者下載到自己的電腦或者手機或者網盤吧。 不要太著急,連接在最后呢 前端 前端框架 node html-cs…

結構化數據建模——titanic數據集的模型建立和訓練(Pytorch版)

本文參考《20天吃透Pytorch》來實現titanic數據集的模型建立和訓練 在書中理論的同時加入自己的理解。 一,準備數據 數據加載 titanic數據集的目標是根據乘客信息預測他們在Titanic號撞擊冰山沉沒后能否生存。 結構化數據一般會使用Pandas中的DataFrame進行預處理…

比賽,幸福度_幸福與生活滿意度

比賽,幸福度What is the purpose of life? Is that to be happy? Why people go through all the pain and hardship? Is it to achieve happiness in some way?人生的目的是什么? 那是幸福嗎? 人們為什么要經歷所有的痛苦和磨難? 是通過…

帶有postgres和jupyter筆記本的Titanic數據集

PostgreSQL is a powerful, open source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance.PostgreSQL是一個功能強大的開源對象關系數據庫系統&am…

Django學習--數據庫同步操作技巧

同步數據庫:使用上述兩條命令同步數據庫1.認識migrations目錄:migrations目錄作用:用來存放通過makemigrations命令生成的數據庫腳本,里面的生成的腳本不要輕易修改。要正常的使用數據庫同步的功能,app目錄下必須要有m…

《20天吃透Pytorch》Pytorch自動微分機制學習

自動微分機制 Pytorch一般通過反向傳播 backward 方法 實現這種求梯度計算。該方法求得的梯度將存在對應自變量張量的grad屬性下。 除此之外,也能夠調用torch.autograd.grad 函數來實現求梯度計算。 這就是Pytorch的自動微分機制。 一,利用backward方…

React 新 Context API 在前端狀態管理的實踐

2019獨角獸企業重金招聘Python工程師標準>>> 本文轉載至:今日頭條技術博客 眾所周知,React的單向數據流模式導致狀態只能一級一級的由父組件傳遞到子組件,在大中型應用中較為繁瑣不好管理,通常我們需要使用Redux來幫助…

機器學習模型 非線性模型_機器學習模型說明

機器學習模型 非線性模型A Case Study of Shap and pdp using Diabetes dataset使用糖尿病數據集對Shap和pdp進行案例研究 Explaining Machine Learning Models has always been a difficult concept to comprehend in which model results and performance stay black box (h…

5分鐘內完成胸部CT掃描機器學習

This post provides an overview of chest CT scan machine learning organized by clinical goal, data representation, task, and model.這篇文章按臨床目標,數據表示,任務和模型組織了胸部CT掃描機器學習的概述。 A chest CT scan is a grayscale 3…

Pytorch高階API示范——線性回歸模型

本文與《20天吃透Pytorch》有所不同,《20天吃透Pytorch》中是繼承之前的模型進行擬合,本文是單獨建立網絡進行擬合。 代碼實現: import torch import numpy as np import matplotlib.pyplot as plt import pandas as pd from torch import …

vue 上傳圖片限制大小和格式

<div class"upload-box clear"><span class"fl">上傳圖片</span><div class"artistDet-logo-box fl"><el-upload :action"this.baseServerUrl/fileUpload/uploadPic?filepathartwork" list-type"pic…

作業要求 20181023-3 每周例行報告

本周要求參見&#xff1a;https://edu.cnblogs.com/campus/nenu/2018fall/homework/2282 1、本周PSP 總計&#xff1a;927min 2、本周進度條 代碼行數 博文字數 用到的軟件工程知識點 217 757 PSP、版本控制 3、累積進度圖 &#xff08;1&#xff09;累積代碼折線圖 &…

算命數據_未來的數據科學家或算命精神向導

算命數據Real Estate Sale Prices, Regression, and Classification: Data Science is the Future of Fortune Telling房地產銷售價格&#xff0c;回歸和分類&#xff1a;數據科學是算命的未來 As we all know, I am unusually blessed with totally-real psychic abilities.眾…

openai-gpt_為什么到處都看到GPT-3?

openai-gptDisclaimer: My opinions are informed by my experience maintaining Cortex, an open source platform for machine learning engineering.免責聲明&#xff1a;我的看法是基于我維護 機器學習工程的開源平臺 Cortex的 經驗而 得出 的。 If you frequent any part…

Pytorch高階API示范——DNN二分類模型

代碼部分&#xff1a; import numpy as np import pandas as pd from matplotlib import pyplot as plt import torch from torch import nn import torch.nn.functional as F from torch.utils.data import Dataset,DataLoader,TensorDataset""" 準備數據 &qu…

OO期末總結

$0 寫在前面 善始善終&#xff0c;臨近期末&#xff0c;為一學期的收獲和努力畫一個圓滿的句號。 $1 測試與正確性論證的比較 $1-0 什么是測試&#xff1f; 測試是使用人工操作或者程序自動運行的方式來檢驗它是否滿足規定的需求或弄清預期結果與實際結果之間的差別的過程。 它…

puppet puppet模塊、file模塊

轉載&#xff1a;http://blog.51cto.com/ywzhou/1577356 作用&#xff1a;通過puppet模塊自動控制客戶端的puppet配置&#xff0c;當需要修改客戶端的puppet配置時不用在客戶端一一設置。 1、服務端配置puppet模塊 &#xff08;1&#xff09;模塊清單 [rootpuppet ~]# tree /et…

數據可視化及其重要性:Python

Data visualization is an important skill to possess for anyone trying to extract and communicate insights from data. In the field of machine learning, visualization plays a key role throughout the entire process of analysis.對于任何試圖從數據中提取和傳達見…