voronoiTreemap包-绘制沃罗诺伊树图
Xwxyturbo
/ 2022-11-20
library(voronoiTreemap)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.5
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(writexl)
library(readxl)
df <- read_xlsx("D:/wenyu/Rrojects/vTreemap/df.xlsx")
df %>%
knitr::kable()
h1 |
h2 |
h3 |
color |
weight |
codes |
province |
prod |
Total |
East |
Anhui |
#CED7BA |
4.35 |
AH |
AH |
95.20 |
Total |
North |
Beijing |
#009593 |
5.05 |
BJ |
BJ |
110.30 |
Total |
South |
Chongqing |
#E4D1B3 |
3.80 |
CQ |
CQ |
82.90 |
Total |
South |
Fujian |
#E4D1B3 |
4.88 |
FJ |
FJ |
106.60 |
Total |
South |
Guangdong |
#E4D1B3 |
4.66 |
GD |
GD |
101.70 |
Total |
North |
Gansu |
#009593 |
1.72 |
GS |
GS |
37.60 |
Total |
South |
Guangxi |
#E4D1B3 |
4.04 |
GX |
GX |
88.10 |
Total |
South |
Guizhou |
#E4D1B3 |
3.11 |
GZ |
GZ |
67.90 |
Total |
East |
Henan |
#CED7BA |
3.55 |
HA |
HA |
77.60 |
Total |
East |
Hubei |
#CED7BA |
4.19 |
HB |
HB |
91.40 |
Total |
North |
Hebei |
#009593 |
3.25 |
HE |
HE |
71.00 |
Total |
South |
Hainan |
#E4D1B3 |
3.56 |
HI |
HI |
77.80 |
Total |
Nodata |
Hongkonng |
#D35C79 |
0.01 |
HK |
HK |
0.01 |
Total |
North |
Heilongjiang |
#009593 |
0.52 |
HL |
HL |
11.40 |
Total |
South |
Hunan |
#E4D1B3 |
3.75 |
HN |
HN |
81.90 |
Total |
North |
Jilin |
#009593 |
0.65 |
JL |
JL |
14.10 |
Total |
East |
Jiangsu |
#CED7BA |
4.47 |
JS |
JS |
97.50 |
Total |
South |
Jiangxi |
#E4D1B3 |
4.03 |
JX |
JX |
88.00 |
Total |
North |
Liaoning |
#009593 |
1.44 |
LN |
LN |
31.50 |
Total |
Nodata |
Macao |
#D35C79 |
0.01 |
MO |
MO |
0.01 |
Total |
North |
InnerMongoriaIM |
#009593 |
1.36 |
NM |
NM |
29.60 |
Total |
North |
Ningxia |
#009593 |
2.49 |
NX |
NX |
54.30 |
Total |
North |
Qinghai |
#009593 |
1.95 |
QH |
QH |
42.60 |
Total |
South |
Sichuan |
#E4D1B3 |
3.81 |
SC |
SC |
83.10 |
Total |
East |
Shandong |
#CED7BA |
4.13 |
SD |
SD |
90.10 |
Total |
East |
Shanghai |
#CED7BA |
4.20 |
SH |
SH |
91.60 |
Total |
North |
Shanxi |
#009593 |
2.60 |
SN |
SX |
29.30 |
Total |
North |
Shaanxi |
#009593 |
1.34 |
SX |
SX |
56.80 |
Total |
North |
Tianjing |
#009593 |
4.37 |
TJ |
TJ |
95.50 |
Total |
Nodata |
Taiwan |
#D35C79 |
0.01 |
TW |
TW |
0.01 |
Total |
North |
Xingjiang |
#009593 |
3.76 |
XJ |
XJ |
82.10 |
Total |
South |
Xizang |
#E4D1B3 |
0.55 |
XZ |
XZ |
11.90 |
Total |
South |
Yunnan |
#E4D1B3 |
3.87 |
YN |
YN |
84.40 |
Total |
East |
Zhejiang |
#CED7BA |
4.54 |
ZJ |
ZJ |
99.10 |
solar_json <- vt_export_json(vt_input_from_df(df,
scaleToPerc = FALSE,
hierachyVar0 = "h1",
hierachyVar1 = "h2",
hierachyVar2 = "h3",
colorVar = "color",
weightVar="prod",
labelVar = "codes"))
vt_d3(solar_json,label = T,
color_border = "#000000",
legend = TRUE, legend_title = "Urban Economic Region",
seed = 2,
size_border = "1px")