Create waffle chart in ggplot2

梦想与她 提交于 2020-07-09 06:23:56

问题


I'm trying to create a graph like this:

in ggplot2.

The idea is to visualize the distribution of True/False values, i.e. in the upper bar 3 out of 80 and in the lower bar 2 out of 280. How would one do this in ggplot2?


回答1:


You can use the waffle package.

library(waffle)

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

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

This is how you could combine two charts like in the graph above

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



来源:https://stackoverflow.com/questions/49997291/create-waffle-chart-in-ggplot2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!