【问题标题】:Make waffle charts with ggplots使用 ggplots 制作华夫饼图
【发布时间】:2019-11-10 12:15:54
【问题描述】:

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

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

  • 有什么方法可以逐行填充华夫饼图(例如 Tableau 示例)不是按列?
  • 是否可以在华夫饼图中添加标签百分比 (24%)?

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

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

哪个会返回这个

【问题讨论】:

    标签: r ggplot2 waffle-chart


    【解决方案1】:

    应该这样做:

    # 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], "%"))
    

    【讨论】:

      猜你喜欢
      • 2017-05-14
      • 2022-07-11
      • 1970-01-01
      • 1970-01-01
      • 2018-10-04
      • 2019-01-01
      • 1970-01-01
      相关资源
      最近更新 更多