【问题标题】:Waffle chart with time on x axisx 轴上带有时间的华夫饼图
【发布时间】:2020-07-17 07:47:17
【问题描述】:

我想在 R 的 x 轴上绘制一个带有时间的华夫饼图,类似于下面的这个。有人可以帮忙吗?谢谢。

数据集在这里:

df <- data.frame(spec = c("Rehab", "Cardiology", "Endocrine", "Respiratory", "General Surgery"), 
                 start.month = c(11,11,7,3,1) )

【问题讨论】:

    标签: r waffle-chart


    【解决方案1】:

    也许是这样的?

    library(ggplot2)
    
    df2 <- do.call(rbind, lapply(seq(nrow(df)), function(i)
      data.frame(month = factor(month.abb[12:df$start.month[i]], levels = month.abb),
                                spec = df$spec[i])))
    df2$spec <- factor(df2$spec, levels = names(rev(sort(table(df2$spec)))))
    
    ggplot(df2, aes(month, spec, colour = spec)) + 
      geom_point(size = 8, shape = 15) +
      coord_cartesian(ylim = c(1, 9)) +
      labs(y = "Cumulative no. of specialties",
           x = "Months",
           colour = "Specialties") +
      scale_color_manual(values = c("#ffc000", "#ed7d31", "#5a9bd5",
                                    "#70ad46", "#44546b")) +
      theme_classic() +
      theme(axis.text.y.left = element_blank(), 
            axis.ticks.length.y = unit(0, "points"),
            legend.background = element_rect(colour = "black"),
            axis.text = element_text(size = 16),
            axis.title = element_text(size = 16))
    

    【讨论】:

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