I have a dataset simplified as follows:
print(data) Team Colour A Red B Red C Blue D Green
I want to produce a waffle chart (square pie chart) of this data. I can do this very easily through:
waffle(c(Red = sum(data$Colour == "Red"), Blue = sum(data$Colour = "Blue"), Green = sum(data$colour = "Green")))
However, I cannot seem to find an easy way to produce the named integer created within the waffle function above, through manipulation of my dataset. I need it to be produced directly from the original dataset as I will need it to be a reactive function within a shiny app.
I have tried using
group_by within dplyr:
forwaffle <- data%>% group_by(Colour) summarise(frequency=n())
However, I cannot convert this list into the required named integer. I have tried using
unlist() but neither of these achieve my desired result.