如何在不重新缩放结果的情况下使用ggradar

时间:2019-03-19 14:26:51

标签: r ggplot2

阅读ggradar文档和错误讨论页面,以使用ggradar,必须首先重新缩放数据,这会改变我的数据结构。尽管我在下载ggiraph::ggRadar

时遇到困难,但我不仅限于使用ggradar

当前结果是按比例缩放的百分比:

enter image description here

鉴于此,我希望根据分组变量(域)的平均值对其进行缩放,使其看起来像这样:

enter image description here

用于创建第一个ggradar图形的数据:

library(tidyverse)
library(scales)
library(ggradar)

df <- tribble(~Question_Code,   ~RespondentLevel,
"Engagement - Inclusion",   5,
"External engagement - policies",   2,
"External engagement - technology", 5,
"Community data",   5,
"Internal engagement",  5,
"Internal use of technology",   4,
"Familiarity/Alignment",    5,
"Environmental impacts",    5,
"Innovation",   2,
"Use of open-source technology",    2,
"Regulation of hardware & software",    5,
"In-house technical capacity",  5,
"Infrastructure procurement",   5,
"Algorithmic Error & Bias", 2,
"Control: Privacy", 5,
"Accountability in Governance Structures",  3,
"Open procurement", 5,
"Use in decision-making",   1,
"Accountability",   1,
"External Control", 4,
"Internal Control", 2,
"Open Data",    2)

#add the grouping variable:
df <- df %>% mutate(Domain = c(as.character((rep("Domain 1", 5))),
                  as.character(rep("Domain 2", 4)),
                  as.character(rep("Domain 3", 6)),
                  as.character(rep("Domain 4", 7))))



对于图形本身:

df %>% mutate(ID = 1) %>% spread(Domain, RespondentLevel, fill = 0)%>%
  mutate_at(vars(`Domain 1`:`Domain 4`), rescale) %>% 
  select(ID, `Domain 1`:`Domain 4`) %>% 
  ggradar(legend.position = "none")

当总结为平均值时,重新缩放的值太小而无法使用,尽管我需要的是按Domain分组的RespondentLevel变量的平均值。

0 个答案:

没有答案