❝本节来介绍一款R包「ggbrick」其最主要用来绘制砖块风格的华夫图,小编测试后发现挺有趣的从此又多了一种图形展示方式。感兴趣的朋友欢迎分享转发,「更多详细内容请参考作者官方文档」 ❞
❝https://github.com/doehm/ggbrick ❞
remotes::install_local("ggbrick-main.zip",upgrade = F,dependencies = T)
devtools::install_github("doehm/ggbrick")
library(tidyverse)
library(ggbrick)
library(waffle)
x <- c(30, 25, 20, 5)
waffle(x, rows = 8)
d10 <- c("#788FCE","#E6956F","#A6BA96","#BD8184","#F2CC8F","#C5E8E3",
"#F4F1DE", "#CDC3D4", "#A88AD2", "#60627C")
mpg |>
count(class, drv) |>
ggplot() +
geom_brick(aes(class, n, fill = drv)) +
scale_fill_manual(values = d10)
❝设置type = 'random'可随机进行填充 ❞
mpg |>
count(class, drv) |>
ggplot() +
geom_brick(aes(class, n, fill = drv),type = 'random') +
scale_fill_manual(values = d10)
mpg |>
count(class, trans) |>
mutate(n = 5*n) |>
ggplot() +
geom_brick(aes(class, n, fill = trans)) +
scale_fill_manual(values = d10)
ggplot() +
geom_brick(aes(x = 1, y = 96), fill = "grey", bricks_per_layer = 8)+
theme_void()