# Creating one circle
library(ggplot2)
one_circle <- circle_data(x = 0, y = 0, radius = 5)
# Plot The Data
one_circle |>
ggplot(aes(x, y)) +
geom_path(color = "green") +
coord_equal()
# To create multiple circles, use your preferred method of iteration:
# Creating two circles
library(purrr)
library(dplyr)
# Make your specs
x_vals <- c(0, 10)
y_vals <- c(0, 0)
radi <- c(1, 3)
fills <- c("purple", "yellow")
circle_n <- 1:2
# Prep for your iteration
lst_circle_specs <-
list(
x_vals,
y_vals,
radi,
fills,
circle_n
)
# Use `circle_data()` in your preferred iteration methods
two_circles <- pmap(lst_circle_specs, ~ circle_data(
x = ..1,
y = ..2,
radi = ..3,
fill = ..4,
color = "#000000",
group_var = TRUE
) |>
# circle_data adds a `group` variable if `group_var` = TRUE.
# For multiple circles, a unique identifier should be added/pasted in.
mutate(group = paste0(group, ..5))) |>
list_rbind()
# Plot the data
two_circles |>
ggplot(aes(x, y, group = group)) +
theme(legend.position = "none") +
geom_polygon(
color = two_circles$color,
fill = two_circles$fill
) +
coord_equal() #Always use coord_equal() or coord_fixed for circles!
Run the code above in your browser using DataLab