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

August 6, 2019
By

[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 = "https://cinc.rud.is")
# or
devtools::install_git("https://git.rud.is/hrbrmstr/waffle.git")
# or
devtools::install_github("hrbrmstr/waffle")

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

library(waffle)
## 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: https://www.kaggle.com/nulldata/hacker-women-in-tech-hackerrank-analysis

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

Waffle in Action

library(waffle)
library(ggplot2)

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

Summary

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.

References

To leave a comment for the author, please follow the link and comment on their blog: r-bloggers on Programming with R.

R-bloggers.com 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.



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

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)