这里是数据:
df <- structure(list(country = c("Australia", "Australia", "Australia",
"South Korea", "South Korea", "South Korea"), parts = c("case_1",
"case_2", "non_case", "case_1", "case_2", "non_case"), values = c(1,
19, 80, 1, 29, 70)), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
library(tidyverse)
library(waffle)
df %>% ggplot(aes(label = parts, values = values)) +
geom_pictogram(n_rows = 10, aes(color = parts),
family = 'fontawesome-webfont',
flip = TRUE,
size = 6,
show.legend = FALSE,
make_proportional = TRUE
) +
scale_label_pictogram(
name = "Confirmed cases",
values = c("male"),
) +
coord_equal() +theme_minimal() +
facet_wrap(~country, nrow = 2, strip.position = "top")
在上述代码中,我生成了以下华夫饼图。使用
make_proportional = TRUE
和n_rows = 10
,我预期每个国家会得到100个图标,但是对于韩国只得到了99个。唯一解决这个问题的方法是先计算所有比例,然后使用make_proportional = FALSE
,但这需要一些时间。此外,我觉得这有点奇怪。如果有人能帮我解决这个问题,我将不胜感激。
Error in geom_pictogram(n_rows = 10, aes(color = parts), family = "fontawesome-webfont", : could not find function "geom_pictogram"
- TarJaedevtools::install_github("hrbrmstr/waffle")
。 - Quinten