r - 在 ggplot2 中创建华夫饼图

标签 r ggplot2 waffle-chart

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

Plot of filled stacked squares

ggplot2 中。

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

最佳答案

您可以使用 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

关于r - 在 ggplot2 中创建华夫饼图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49997291/

相关文章:

r - 将列表组件组合成一个向量

r - 如何使 R-GUI 作为独立应用程序或可执行平台独立软件

r - 从 R 中的线性模型列表映射 emmeans

r - 来自预先计算值的 ggplot errorbars

r - 通缉 : repeated-pictogram visualization of population split

r - R 中的 Font Awesome 已加载,但 waffle 未找到

r - 为什么使用 NGramTokenizer 时 R 会挂起?

r - ggplot : Using strip. text.x (element_text) 用于仅制作刻面轴标签 "bold"的一个元素

r - 如何获得具有相同比例的多个ggplot2scale_fill_gradientn?