#Source: https://t.me/rstudioprogr
library(ggplot2)
library(dplyr)
library(packcircles)
library(viridis)
# создаем датасет вручную
df_counts <- data.frame(
Country = c("Австралия","Аргентина","Бразилия","Венгрия",
"Венесуэла","Вьетнам","Греция","Индия","Испания","Италия",
"Канада","Китай","Колумбия","Нигерия","Норвегия","Оман",
"Россия","Румыния","США","Саудовская Аравия","Таиланд",
"Тайвань","Турция","Финляндия","Франция","Южная Корея"),
n = c(51,20,21,22,8,10,34,91,24,19,177,59,15,18,20,21,108,22,402,2,14,9,11,19,25,17))
# добавляем id
df_counts$id <- 1:nrow(df_counts)
# layout кругов
packing <- circleProgressiveLayout(df_counts$n, sizetype = "area")
# полигоны кругов
dat <- circleLayoutVertices(packing, npoints = 50) %>%
left_join(df_counts, by = "id")
# подписи
labels <- df_counts %>%
bind_cols(packing) %>%
mutate(label = paste0(Country, "\n(", n, ")"), text_color = "white")
# график
ggplot() + geom_polygon(data = dat, aes(x, y, group = id, fill = n),
color = "white", size = 0.3, alpha = 0.95) +
geom_text(data = labels %>% filter(n > 20),
aes(x = x, y = y, label = label, color = text_color),
size = 4.5, lineheight = 0.9, fontface = "bold") +
scale_fill_viridis(option = "D", begin = 0.1, end = 0.5) +
scale_color_identity() +
coord_equal() +
theme_void() +
theme(legend.position = "right")

ggsave("circles_plot.svg", width = 10, height = 8)