答案 0 :(得分:8)
此类可视化称为树形图。适当地,您可以使用treemap
包。您可以找到treemap
here的详细教程,但我会向您展示基础知识。下面我将向您展示如何在ggplot2
中创建树形图。
library(treemap)
cars <- mtcars
cars$carname <- rownames(cars)
treemap(
cars,
index = "carname",
vSize = "disp",
vColor = "cyl",
type = "value",
format.legend = list(scientific = FALSE, big.mark = " ")
)
在github上还有一个用于使用ggplot2
创建树形图的开发包。 Here's the repo用于安装软件包。
library(tidyverse)
library("ggfittext")
library("treemapify")
cars <- mtcars
cars$carname <- rownames(cars)
cars <- mutate(cars, cyl = factor(cyl))
ggplot(cars, aes(area = disp, fill = cyl, label = carname)) +
geom_treemap() +
geom_treemap_text(
fontface = "italic",
colour = "white",
place = "centre",
grow = TRUE
)