0

I understand this question has been asked before, but in using some of the past answers I still cannot produce the radar chart I would like. I have used this, as an example of a radar chart I am trying to reproduce. But I can't seem to figure out the last bits.

This is what I have so far:enter image description here

I am a unhappy with the following: 1. The polar grid on the background. How do I create one such that it does go through the middle of every bar? It looks like it does at first, but then stops and I cannot figure out why. If I cannot make it go through the middle, then I would like it to go on the outside of each bar. If that doesn't work, then maybe just slice the radar chart into 8 equal sections? 2. Why is there a width between some bars, but others not so much.

Code:

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

1 Answer 1

1

If you look closely the example you link to, they create the plot using a factor. You are using a numeric (continuous) variable. I coerce angle_bucket to factor.

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)

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

I know I did not ask this orginally. Is there a way to remove the extra spacing? As in remove the last section of the circle above the highest bar.
@JackArmstrong settings scale limits didn't work. I'd have to research this a bit more but I'm pressed for time right now. My suggestion would be to post this as a new question.
You have to draw in the polar grid yourself with horizontal and vertical lines. I will post when I have a chance as part of the original question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.