У меня есть фрейм данных, который выглядит так, и я хочу создать с ним круговую диаграмму Вороного.
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
Created on 2022-04-08 by the reprex package (v2.0.1)
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()
Created on 2022-04-08 by the reprex package (v2.0.1)
Кто-нибудь знает, как я могу сделать его круглым? Я нашел эту ссылку на github, но в ней отсутствуют данные, которые мне нужны для преобразования многоугольников в круговой вороной. https://github.com/nrennie/30DayChartChallenge/blob/main/2022/scripts/04_flora.R
Связанное изображение представляет собой древовидную карту Вороного. Существует пакет R под названием voronoiTreemap
, который вы можете использовать, чтобы создать его самостоятельно:
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))