rggplot2chartspowerbidonut-chart

ggplot create dynamic multi KPIs donut in one chart


I have a projects list with dynamic KPIs per project, each KPI has (a value and target)

I am receiving the dataset in the below format, I am trying to drow one chart for kpi for one project :

dataset <- data.frame(
  value = c(3,5,200.....), 
  Target = c(10,20,250.....), 
  KPI = c("a","b","c","d",....)
)

Is there any way to achieve multi-donut KPIs using ggplot!! (or even a pie chart) to look similar to the below image!

enter image description here


Solution

  • You could do:

    library(tidyverse)
    
    dataset %>%
      mutate(perc = value/Target) %>%
      ggplot(aes(x = 3, y = perc)) +
      geom_linerange(aes(ymin = 0, ymax = 1), size = 4, color = "#caeee3") +
      geom_linerange(aes(ymin = 0, ymax = perc), size = 4, color = "#01b8aa") +
      geom_text(aes(x = 1.5, y = 0, label = scales::percent(perc)), size = 6) +
      geom_text(aes(x = 0, y = 0, label = KPI), size = 8, color = 'gray80') +
      coord_polar(theta = 'y') +
      theme_void() +
      scale_x_continuous(limits = c(0, 4), expand = c(0, 0)) + 
      facet_wrap(.~KPI) +
      theme(strip.text = element_blank())
    

    enter image description here