在ggplot2中创建华夫饼图

时间:2018-04-24 08:51:42

标签: r ggplot2 waffle-chart

我试图像这样创建一个图表:

Plot of filled stacked squares

ggplot2中的

这个想法是可视化真/假值的分布,即在80中的上方栏3和280中的下栏2中。 如何在ggplot2中执行此操作?

1 个答案:

答案 0 :(得分:4)

您可以使用waffle package

library(waffle)

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

enter image description here

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"
  )
)

enter image description here

相关问题