繁体   English   中英

在ggplot2中创建华夫饼图

[英]Create waffle chart in ggplot2

我正在尝试创建一个像这样的图:

实心堆积正方形图

ggplot2

这个想法是可视化True / False值的分布,即在80中的上条3中和在280中的下条2中。在ggplot2怎么做?

您可以使用waffle包装

library(waffle)

parts <- c('TRUE' = 3, 'FALSE' = 77)
p <- waffle(parts, rows = 8, colors = c("black", "grey70"))
p

在此处输入图片说明

class(p)
#[1] "gg"     "ggplot"

这样可以合并两个图表,如上图所示

iron(
  waffle(
    c('TRUE' = 3, 'FALSE' = 77),
    colors = c("black", "grey70"),
    size = 0.5,
    pad = 20,
    legend_pos = "none"
  ),
  waffle(
    c('TRUE' = 2, 'FALSE' = 278),
    colors = c("black", "grey70"),
    size = 0.5,
    legend_pos = "bottom"
  )
)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM