在 ggplot2 中创建华夫饼图

Luk*_*rau 2 r ggplot2 waffle-chart

我正在尝试创建这样的图表:

填充的堆叠方块图

在ggplot2。

这个想法是将真/假值的分布可视化,即在 80 个中的第 3 个上条和 280 个中的第 2 个下条中。如何做到这一点ggplot2?

mar*_*kus 7

您可以使用该waffle包。

library(waffle)

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

在此处输入图片说明

class(p)
#[1] "gg"     "ggplot"
Run Code Online (Sandbox Code Playgroud)

这就是您如何组合上图中的两个图表

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"
  )
)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明