雷达图上的误差条? [英] Error bars on a radar plot?

查看:83
本文介绍了雷达图上的误差条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望为多变量数据制作雷达图,这是一项对 excel 来说足够简单的任务.

当我还想绘制一些误差线时,问题就出现了.据我了解,我无法在 excel 中做到这一点.这在 R 上可行吗?

或者有人可以提出替代方案吗?我有 32 个单值维度.

谢谢!

解决方案

我不太喜欢雷达图,但这里有一些想法可以帮助你前进,借鉴

# 选项 2:我的数据%>%收集(测量,值,-变量,-stderr)%>%ggplot(aes(x = 变量,y = 值,颜色 = 度量,组 = 度量,线型 = 度量)) +geom_polygon(fill = NA) +theme_light() +主题(panel.grid.minor = element_blank()) +coord_polar() +scale_colour_manual(values = c("steelblue", "black", "steelblue")) +scale_linetype_manual(values = c(2,1,2)) +实验室(x =",y =")

# 选项 3:我的数据%>%ggplot(aes(x = 变量,y = 中点,组 = 1)) +geom_polygon(fill = NA, color = "purple") +geom_segment(aes(xend = 变量,y = 下,yend = 上),颜色 = "grey50") +geom_point(颜色=紫色")+theme_light() +主题(panel.grid.minor = element_blank()) +主题(panel.grid.major.x = element_blank()) +coord_polar() +实验室(x =",y =")

编辑/添加

我想我更喜欢这个:

# 选项 4:我的数据%>%ggplot(aes(x = 变量,y = 中点,组 = 1)) +geom_polygon(aes(y = upper), fill = "grey50", alpha = 0.5) +geom_polygon(aes(y = lower), fill = "grey99", alpha = 0.7) +geom_polygon(fill = NA, color = "purple") +theme_light() +主题(panel.grid.minor = element_blank()) +coord_polar() +实验室(x =",y =")

I'm looking to make a radar plot for multivariate data, a task simple enough for excel.

The problem comes when I would like to also plot some error bars on this. From what I understand, I cannot do this in excel. Is this possible on R?

Or can someone suggest an alternative? I have 32 single value dimensions.

Thanks!

解决方案

I don't much like radar charts but here are some ideas to get you going, drawing on this approach. I like the look of my option 1 best, but I'm not sure how to solve the gap between var32 and var1 (I have some ideas, but a bit awkward).

library(tidyverse)
library(ggplot2)
library(scales)

# make some mock data
mydata <- data.frame(variable = paste0("Var", 1:32),
                     midpoint = rnorm(32),
                     stderr = rnorm(32, 1, 0.1),
                     stringsAsFactors = FALSE) %>%
  mutate(upper = midpoint + 1.96 * stderr,
         lower = midpoint - 1.96 * stderr) %>%
  mutate(variable = factor(variable, levels = variable)) 

# Option 1:
mydata %>%
  ggplot(aes(x = variable, y = midpoint, group = 1)) +
  geom_ribbon(aes(ymin = lower, ymax = upper), fill = "grey50", alpha = 0.5) +
  geom_line(colour = "purple") +
  theme_light() +
  theme(panel.grid.minor = element_blank()) + 
  coord_polar() +
  labs(x = "", y = "")

# Option 2:
mydata %>%
  gather(measure, value, -variable, -stderr) %>%
  ggplot(aes(x = variable, y = value, colour = measure, group = measure, linetype = measure)) +
  geom_polygon(fill = NA) +
  theme_light() +
  theme(panel.grid.minor = element_blank()) + 
  coord_polar() +
  scale_colour_manual(values = c("steelblue", "black", "steelblue")) +
  scale_linetype_manual(values = c(2,1,2)) +
  labs(x = "", y = "")

# Option 3:
mydata %>%
  ggplot(aes(x = variable, y = midpoint, group = 1)) +
  geom_polygon(fill = NA, colour = "purple") +
  geom_segment(aes(xend = variable, y = lower, yend = upper), colour = "grey50") +
  geom_point(colour = "purple") +
  theme_light() +
  theme(panel.grid.minor = element_blank()) + 
  theme(panel.grid.major.x = element_blank()) +
  coord_polar() +
  labs(x = "", y = "")

Edit / addition

I think I prefer this one:

# Option 4:
mydata %>%
  ggplot(aes(x = variable, y = midpoint, group = 1)) +
  geom_polygon(aes(y = upper), fill = "grey50", alpha = 0.5) +
  geom_polygon(aes(y = lower), fill = "grey99", alpha = 0.7) +
  geom_polygon(fill = NA, colour = "purple") +
  theme_light() +
  theme(panel.grid.minor = element_blank()) + 
  coord_polar() +
  labs(x = "", y = "")

这篇关于雷达图上的误差条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆