Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading