rggplot2radar-chart

How can I adjust lines in a radar plot made with ggplot2?


I would like to make a radar graph in ggplot for the following data set:

Types Risk_Value
1 Resiliency Risk          1
2       Data Risk          2
3  Financial Risk          1
4       Tool Risk          1
5      Other Risk          1

My code so far:

plot = ggplot(data = RiskPlot, aes(x=substr(Types,1,1), y = Risk_Value, fill = Types)) +
      geom_bar(stat = "identity")+
      theme_minimal()+
      theme( text = element_text(size = 35),
             panel.border = element_blank(),
             panel.background = element_blank(),
             axis.title = element_blank(),
             axis.text.y = element_blank(),
             legend.text=element_text(size=25),
             legend.position = "left") +
      coord_polar(start =0) +
      ylim(-1,3) +
      annotate(
        x = .5, 
        y = 1, 
        label = "Low", 
        geom = "text",
        size = 10
      ) +
      annotate(
        x = .5, 
        y = 3, 
        label = "High", 
        geom = "text",
        size = 10
      ) + guides(fill=guide_legend(title=NULL))

It produces this chart below:

Sample chart

I feel that I'm 99% there, but would love to change the following: (1) any way to remove the outmost ring, and (2) would it be possible to remove the lines in the middle with plain white (i.e. have the middle circle just be the background color)?

Any help would be appreciated,

Philipp


Solution

  • Remove the gridlines entirely, and use annotations to draw only the desired lines. From a visualization point of view, it may be best to directly label the segments using coord_curvedpolar from geomtextpath, and keep the fill color to highlight the risk score.

    Incidentally, this is not a radar plot. It is a polar bar plot.

    library(geomtextpath)
    
    ggplot(RiskPlot, aes(Types, Risk_Value, fill = Risk_Value)) +
      geom_blank() +
      annotate("segment", x = 0.5 + 0:4, y = rep(0, 5), xend = 0.5 + 0:4,
               yend = rep(2, 5), colour = "gray", linewidth = 0.5) +
      geom_hline(yintercept = c(0, 1, 2), color = "gray", linewidth = 0.5) +
      geom_col(width = 1, col = "#ffffff80", linewidth = 0.5, alpha = 0.8) +
      coord_curvedpolar(start = 2*pi/10) +
      scale_fill_gradient(low = "green4", high = "red3") +
      ylim(-1, 2) +
      annotate("text", x = c(5, 5), y = c(0.5, 1.5), 
               label = c("Low", "High"), size = 10) +
      theme_minimal() +
      theme( text = element_text(size = 10 * .pt),
             panel.border = element_blank(),
             panel.background = element_blank(),
             axis.title = element_blank(),
             axis.text.y = element_blank(),
             axis.text.x = element_text(vjust = 1),
             legend.position = "none",
             panel.grid = element_blank()) 
    

    enter image description here