简体   繁体   English

使用 ggplot 在 R 中创建 360 度分析

[英]Create 360 Degree Analysis in R using ggplot

Is it possible to create a 360-degree analysis in R using ggplot or other similar packages?是否可以使用 ggplot 或其他类似软件包在 R 中创建 360 度分析?

Sample data frame below, describing 4 athletes with their speed, strength, skill, stamina and spirit (all between 0 and 5).下面的示例数据框,描述了 4 名运动员的速度、力量、技能、耐力和精神(均在 0 到 5 之间)。

name <- c('John', 'Sam', 'Anthony', 'Frank')
speed <- c(1.5, 3, 2, 4)
strength <- c(3, 2.2, 4, 4.5)
skill <- c(4, 1, 2.5, 1.4)
stamina <- c(5, 3.3, 2, 3.9)
spirit <- c(3, 4, 1.4, 2)
df <- data.frame(name, speed, strength, skill, stamina, spirit)
df

My question is: Is there anything in ggplot or other open source packages, that allows me to create a '360 degree analysis' for each of the athlete?我的问题是:ggplot 或其他开源软件包中是否有任何东西可以让我为每个运动员创建“360 度分析”? Forgive my drawings but this is what I wanted to achieve:原谅我的画,但这是我想要实现的:

360度分析

This graphical form is often called a radar plot ( stars plots and spider plots are similar): you can do this in base R with ?stars , or in ggplot/tidyverse.这种图形形式通常称为雷达 plot星形图蜘蛛图类似):您可以在基础 R 中使用?stars或在 ggplot/tidyverse 中执行此操作。 (I'm guessing that you want a graphical presentation: normally if someone asked for an "analysis" of these data I would assume they wanted to do some kind of multivariate statistical analysis.) (我猜你想要一个图形表示:通常如果有人要求对这些数据进行“分析”,我会假设他们想做某种多元统计分析。)

remotes::install_github("ricardo-bion/ggradar")
library(ggradar)
library(dplyr)
df_scale <- df %>% mutate(across(where(is.numeric),scales::rescale))

I could have gotten something closer to your example by (1) not rescaling the columns and setting grid.max (and possibly other parameters) accordingly;我可以通过(1)不重新调整列并相应地设置grid.max (可能还有其他参数)来更接近你的示例; (2) computing the average of the rows. (2) 计算行的平均值。

ggradar(df_scale)

雷达图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM