Search code examples
rggplot2ggforce

Draw two circles proportional


I have two counts, one of total numbers of orders, one of unique customers. What I want to make is a plot consisting of two (proportional) circles, an outer one for the total number of order and an inner one for the unique customers.

This is what I got so far, and it's close in terms of how I want it to look, but the circles are not proportional? I'm open to other options than geom_circle. I tried working with geom_point and setting the n to size, but I got two smalls dots in a big empty plot.

library(ggforce) 

X <- structure(list(n = c(16836L, 9017L), Type = c("Total n order", "Unique customers")), 
               row.names = c(NA, -2L), class = c("tbl_df", "tbl", "data.frame"))

ggplot(X) + 
  geom_circle(
    aes(x0 = 0, y0 = n, r = n),
    linewidth =4,
    colour="black"
  ) + 
  geom_circle(
    aes(x0 = 0, y0 = n, r = n),
    linewidth =1,
    colour = "white"
  ) + 
  coord_flip() + 
  theme(aspect.ratio = 1)

enter image description here


Solution

  • I'd suggest using dedicated Venn Diagram packages. If we want to go with circles then we can extract Radius from Area:

    X$R <- sqrt(X$n/pi)
    
    ggplot(X) + 
      geom_circle(
        aes(x0 = 0, y0 = R, r = R),
        linewidth =4,
        colour="black"
      ) + 
      geom_circle(
        aes(x0 = 0, y0 = R, r = R),
        linewidth =1,
        colour = "white"
      ) + 
      coord_flip() + 
      theme(aspect.ratio = 1)
    

    enter image description here