2

I am trying to create a visual that nests four circles as so:

nestedcircles

The size of the circle depends on a ratio/numeric value relative to the largest circle.

I found this post which seems to provide a solution for two aligned circles: Bubble Chart with bubbles aligned along their bottom edges

However, I am a complete newbie to R and not sure how to proceed to achieve the desired four aligned circles.

Sample input data:

d <- read.table(text = "circle:x
Circle1:340000
Circle2:5000
Circle3:1100
Circle4:340", header = TRUE, sep = ":")

Desired Output of four aligned circles based on input numbers:

nestedcircles

zx8754
  • 52,746
  • 12
  • 114
  • 209
katebeckett
  • 71
  • 11
  • 1
    What does your data look like? What functions are you trying to use to plot such data? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Nov 24 '21 at 07:22
  • Relevant? https://stackoverflow.com/a/52614158/6851825 – Jon Spring Nov 24 '21 at 07:27
  • Updated to add representative sample data. I have been working off of the sample code in the linked Stack Overflow question. Thank you. – katebeckett Nov 24 '21 at 07:29
  • Once you have decided the radius, place the center at coordinates (X, Y-R) where (X, Y) is the bottom point. –  Nov 24 '21 at 12:28

1 Answers1

2

Convert area to radius, then use ggforce to draw circles:

library(ggforce)

#convert area to R
d$r <- sqrt(d$x / pi)
d$x0 <- max(d$r) / 2
d$y0 <- d$r

ggplot(d, aes(x0 = x0, y0 = y0, r = r, fill = circle)) +
  geom_circle() +
  theme_void()

enter image description here

zx8754
  • 52,746
  • 12
  • 114
  • 209
  • Thank you! This worked very well. Is there a way to customize the fill/color of each circle as well? – katebeckett Dec 02 '21 at 13:55
  • @katebeckett Yes, see this post to set your own set of colours manually: https://stackoverflow.com/q/15130497/680068 – zx8754 Dec 02 '21 at 14:16