首页 > 解决方案 > 使用 ggplot 在 R 中创建 360 度分析

问题描述

是否可以使用 ggplot 或其他类似软件包在 R 中创建 360 度分析?

下面的示例数据框,描述了 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

我的问题是:ggplot 或其他开源软件包中是否有任何东西可以让我为每个运动员创建“360 度分析”?原谅我的画,但这是我想要实现的:

360度分析

标签: rggplot2

解决方案


这种图形形式通常称为雷达图星图蜘蛛图类似):您可以在基础 R 中使用?stars或在 ggplot/tidyverse 中执行此操作。(我猜你想要一个图形表示:通常如果有人要求对这些数据进行“分析”,我会假设他们想做某种多元统计分析。)

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

grid.max我可以通过(1)不重新调整列并相应地设置(可能还有其他参数)来更接近您的示例;(2) 计算行的平均值。

ggradar(df_scale)

雷达图


推荐阅读