Draw two circles proportional

84 Views Asked by At

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

2

There are 2 best solutions below

1
On BEST ANSWER

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

0
On

Here's a quick and dirty version using ggvenn. Possibly need more details in the question to understand explicitly what you are attempting to achieve.

library(ggvenn)

X = list("Total n order" = 1:16836,
         "Unique customers" = 1:9017)

ggvenn(X, c("Total n order", "Unique customers"),
       auto_scale = TRUE)

Created on 2023-11-07 with reprex v2.0.2