How to make Square (Pie) Charts for Infographics in R

[This article was first published on r-bloggers on Programming with R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Are you looking for some unique way of visualizing your numbers instead of simply using bar charts – which sometimes could be boring the audience – if used, slide after slide? Here’s Square Pie / Waffle Chart for you.

Waffle Chart or as it goes technically, Square Pie Chart is just is just a pie chart that use squares instead of circles to represent percentages. So, it’s good to keep in mind that this is applicable better for Percentages. Also, Square Pie Chart is a good chart to be added in an Infographic where such visualizations are common but in a corporate set up, I guess this wouldn’t find its day or probably, show up only rarely.

We’re going to use Waffle package by the well-known boB Rudis.

Installation & Loading

install.packages("waffle", repos = "")
# or
# or

Make sure you install using any of the above methods and not from CRAN, as CRAN Package isn’t the latest one

## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.5.2

Use-cse: Stack Overflow Dev Survey Women Respondents

My opinion, with visualizations, the trick is to use the right visualization for the right set of data rather than simply using any because of our fondness. Said that, to make Square Pie Charts let’s try to visualize the percentage of Women respondents on Hackerrank 2018 Developer Survey

# reference:

hr_wo <- data.frame(
  Gender = c("Male","Female"),
  hr_percentage = c(83,17),
  stringsAsFactors = FALSE)

Waffle in Action


  ggplot(data = hr_wo, 
         aes(fill = Gender, values = hr_percentage)) +
  geom_waffle(n_rows = 10, size = 0.5, colour = "#ffffff",      flip = TRUE) +
  scale_fill_manual(values = c("#f59cbf","#00daff")) +
  coord_equal() +
  theme_minimal() +
  theme_enhance_waffle() +
  labs(title = "% Male & Female - Survey Respondents ",
       subtitle = "Hackerrank Developer Survey 2018",
       caption = "Plot made using `waffle` - R package")


That’s a really beautiful plot - aesthetically and also it’s good enough (or IMO better than a typical Pie Chart) in repesenting a realistic picture of the percentages. This ends this quick tutorial to make visualizations with waffle / square pie charts when dealing with percentags.


To leave a comment for the author, please follow the link and comment on their blog: r-bloggers on Programming with R. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)