使用 ggplots 制作华夫饼图

Make waffle charts with ggplots

我正在尝试使用 R 从 Tableau 中重现这样一个简单的华夫饼图:

我不确定在 waffle 包中是否可行,但是我非常感谢对两种情况的任何帮助:

这是我到目前为止的尝试:

 library(waffle)  

 # dummy sample 
 basedata <- c('User'=24, 'Not User'=  76)

 # Waffle chart
 waffle(
   basedata,
   rows = 10 ,
   colors =  c("#636363", "#fee8c8"),
   xlab = "1 square == 1%"
 ) +
   ggtitle("Some tilte") +
   theme(
     plot.title = element_text(hjust = 0.5, size = 27, face = "bold"),
     legend.text = element_text(size = 15),
     legend.position = "bottom"
   )

哪个会return这个

应该这样做:

# dummy sample 
basedata <- c('User'=24, 'Not User'=  76)

# Waffle chart
waffle(
  basedata,
  rows = 10 ,
  colors =  c("#636363", "#fee8c8"),
  xlab = "1 square == 1%",
  flip = TRUE
) +
  ggtitle("Some tilte") +
  theme(
    plot.title = element_text(hjust = 0.5, size = 27, face = "bold"),
    legend.text = element_text(size = 15),
    legend.position = "bottom"
  ) +
  annotate("text", x = 4, y = 5, label = paste(basedata[1], "%"))