Waffle charts are described as squared pie charts. They are used to communicate parts of a whole in regards to categorical quantities, similar to the percentages in a pie chart. It is recommended to keep the number of different categories small so that it can show the difference and be a more descriptive chart.
You can install Waffle with function “install.packages()” and load it with “library(),” but first one has to be sure to have installed and loaded ggplot2 first.
install.packages("ggplot2")
install.packages("waffle")
library(ggplot2)
library(waffle)
Once you have installed the waffle package and load it, you can add a data set that you would like to analyze. For this example, I will be using a data set called “mtcars.” This data from a 1974 Motor Trends US magazine regarding fuel consumption in addition to other aspects of auto design and performance. The set includes information for 32 cars from the years 1973 and 1974. Since a category is needed to be able to try the Waffle package I’ve chosen the number of cylinders for this example. The mtcars has loaded and I used (spec<-table (mtcars$cyl)) to see how many cylinder types there are, which is three 4,6, and 8. The table also tells me how many of cylinders of each category there are. This will help when creating the Waffle chart.
data("mtcars")(spec<-table(mtcars$cyl))##
## 4 6 8
## 11 7 14
Next I call the waffle function for the cylinder category, one can ask for the number of rows preferred, in this case 4 rows were requested and one can also chose where the legend will be placed, I chose the top for this example.
waffle(spec, rows = 4, legend_pos = "top") # Other Options
This is a simple waffle chart, but as mentioned earlier the number of rows can be changed, the colors of the categories, and even a font package called “extrafont” can be added that will allow to have icons instead of squares in the chart.