2

I would like to plot a waffle chart with time on the x-axis in R, similar to this one below. Can anyone help, please? Thanks.

The dataset is here:

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

Image of example waffle chart

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
Tse Lert
  • 192
  • 5

1 Answers1

2

Perhaps something like this?

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

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87