在R中制作圆形Voronoi图

Make a circular Voronoi diagram in R

我有一个看起来像这样的数据框,我想用它创建一个圆形 voronoi 图

df <- data.frame(country = c("Ukraine", "Russia", "Argentina", "China", "Romania", "Other"),
                 prod = c(11.0, 10.6, 3.1, 2.4, 2.1, 15.3))

df
#>     country prod
#> 1   Ukraine 11.0
#> 2    Russia 10.6
#> 3 Argentina  3.1
#> 4     China  2.4
#> 5   Romania  2.1
#> 6     Other 15.3

reprex package (v2.0.1)

于 2022-04-08 创建
library(ggplot2)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library("ggvoronoi")

df <- data.frame(country = c("Ukraine", "Russia", "Argentina", "China", "Romania", "Other"),
                 prod = c(11.0, 10.6, 3.1, 2.4, 2.1, 15.3))

ggplot(df, aes(country, prod)) +
  geom_voronoi(aes(fill=prod)) +
  theme_minimal()

reprex package (v2.0.1)

于 2022-04-08 创建

有没有人知道我如何让它循环? 我找到了这个 github link 但它缺少我需要将多边形转换为圆形 voronoi 的数据 https://github.com/nrennie/30DayChartChallenge/blob/main/2022/scripts/04_flora.R

链接的图片是 Voronoi 树状图。有一个名为 voronoiTreemap 的 R 包,您可以使用它自己创建一个:

library(voronoiTreemap)

vor <- data.frame(h1 = 'World', 
                  h2 = c('Europe', 'Europe', 'Americas', 'Asia',
                         'Europe', 'Other'),
                  h3 = df$country,
                  color = hcl.colors(nrow(df), palette = 'TealRose'),
                  weight = df$prod,
                  codes = df$country)

vt <- vt_input_from_df(vor)

vt_d3(vt_export_json(vt))