问题
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