ggplot 中的雷达图

Radar Plots within ggplot

我知道这个问题以前有人问过,但在使用过去的一些答案时,我仍然无法生成我想要的雷达图。我用过这个,as an example of a radar chart I am trying to reproduce.但我似乎无法弄清楚最后一点。

这是我目前拥有的:

我对以下内容不满意: 1.背景上的极坐标网格。我如何创建一个它确实穿过每个条的中间?一开始看起来是这样,但后来就停止了,我不明白为什么。如果我不能让它穿过中间,那么我希望它在每个条的外侧。如果这不起作用,那么也许只是将雷达图分成 8 个相等的部分? 2. 为什么有的bar之间有宽度,有的没有。

代码:

t<-12
angle_bucket<-seq(0,2*pi-2*pi/t,2*pi/t) 
angle_group<-seq(1,length(angle_bucket),1)                   
meanL<-c(17.289,20.7857,18.675,10.4,0,0,22.1,19.5,18.02,19.5,30.35,29.83)
normized<-c(1,0.368,0.2105,0.05263,0,0,0.10526,0.21056,0.5263,0.157894,0.7368,0.8421)
ang_dfp<-data.frame(angle_bucket,angle_group,meanL,normized) 
ang_dfp$angle_group<-as.factor(ang_dfp$angle_group)
ang_dfp$angle_bucket<-ang_dfp$angle_bucket+2*pi/t/2    
p<-ggplot()+
  geom_bar(data=ang_dfp,aes(x=angle_bucket,y=normized, fill=meanL), stat = "identity")+
  scale_fill_viridis_c(alpha=1,begin=0,end=1,direction=-1,option='plasma',aesthetics ='fill')+
  scale_x_continuous(breaks = 0:nlevels(ang_dfp$angle_group))+
  #Theme
  theme_minimal()+
  theme(
    panel.background = element_rect(fill = "transparent", colour = NA),
    axis.title = element_blank(),
    axis.ticks = element_blank(),
    axis.text=element_blank(),
    axis.line=element_blank(),
    plot.margin = unit(c(0.1,0.1,0.1,0.1), "cm"),
    plot.background = element_rect(fill = "transparent", colour = NA),
    legend.position = 'none'
  )+
  coord_polar(theta='x',start=0,direction=-1)
p

如果您仔细查看您 link 的示例,他们会使用一个因子创建绘图。您正在使用数字(连续)变量。我强迫 angle_bucket 分解。

ggplot() +
  geom_bar(data=ang_dfp,aes(x=as.factor(angle_bucket),y=normized, fill=meanL), stat = "identity")+
  scale_fill_viridis_c(alpha=1,begin=0,end=1,direction=-1,option='plasma',aesthetics ='fill')+
  # scale_x_continuous(breaks = 0:nlevels(ang_dfp$angle_group))+
  #Theme
  theme_minimal()+
  theme(
    panel.background = element_rect(fill = "transparent", colour = NA),
    axis.title = element_blank(),
    axis.ticks = element_blank(),
    axis.text=element_blank(),
    axis.line=element_blank(),
    plot.margin = unit(c(0.1,0.1,0.1,0.1), "cm"),
    plot.background = element_rect(fill = "transparent", colour = NA),
    legend.position = 'none') +
  coord_polar(theta='x',start=0,direction=-1)