Search code examples
rggplot2diagram

Is it possible to draw the following diagram in R?


I wanted to ask if there is any R package that can be used to draw the following diagram?

I have the data in the form of percentages but do not know how to draw such a diagram.

Thank you!

Diagram


Solution

  • I guess if you get your data into this format:

    df <- data.frame(percents = c(51, 48, 46, 41, 29, 25, 34, 18, 18),
                     label = c("MEDICAL\nSCHOOL\nAPPLICANTS", 
                               "MEDICAL\nSCHOOL\nGRADUATES", 
                               "RESIDENTS", 
                               "FACULTY", 
                               "DIVISION\nCHIEFS", 
                               "FULL\nPROFESSORS", 
                               "SENIOR\nASSOCIATE\nDEANS", 
                               "DEPARTMENT\nCHAIRS", "DEANS"))
    df
    #>   percents                       label
    #> 1       51 MEDICAL\nSCHOOL\nAPPLICANTS
    #> 2       48  MEDICAL\nSCHOOL\nGRADUATES
    #> 3       46                   RESIDENTS
    #> 4       41                     FACULTY
    #> 5       29            DIVISION\nCHIEFS
    #> 6       25            FULL\nPROFESSORS
    #> 7       34    SENIOR\nASSOCIATE\nDEANS
    #> 8       18          DEPARTMENT\nCHAIRS
    #> 9       18                       DEANS
    

    Then you could do something like:

    library(ggplot2)
    library(ggforce)
    library(dplyr)
    
    df %>% mutate(r = sqrt(percents), x = r + cumsum(lag(2 * r, default = 0))) %>%
      ggplot() + 
      geom_circle(aes(x0 = x, r = r, y0 = r), size = 3, color = "#0A0A0A5A") +
      geom_text(aes(x = x, y = r, label = paste0(percents, "%"), size = percents),
                fontface = "bold", color = "#643291") +
      geom_text(aes(x = x, y = 20, label = label), vjust = 0,
                fontface = "bold", color = "gray20", size = 3) +
      geom_segment(aes(x = x, xend = x, y = r + 3, yend = 18),
                   color = "#643291", size = 2) +
      coord_equal() +
      scale_y_continuous(limits =c(-5, 25)) +
      scale_size_continuous(range = c(4, 8)) +
      theme_void() +
      theme(legend.position = "none")
    

    enter image description here

    Note that the percentage is proportional to the area of the circles, which is a much more honest way to represent data in this type of plot.