### Installing the waffle R Package Source: https://github.com/hrbrmstr/waffle/blob/master/README.md This snippet demonstrates two methods for installing the 'waffle' R package: from CRAN using `install.packages()` or directly from GitHub using `remotes::install_github()`. The GitHub option requires the 'remotes' package to be installed. ```R install.packages("waffle") # NOTE: CRAN version is 0.7.0 # or remotes::install_github("hrbrmstr/waffle") ``` -------------------------------- ### Loading Libraries and Checking waffle Version Source: https://github.com/hrbrmstr/waffle/blob/master/README.md This R snippet loads necessary packages for using 'waffle' charts, including 'waffle' itself, 'magrittr', 'hrbrthemes', 'ggplot2', and 'dplyr'. It then checks and prints the currently installed version of the 'waffle' package. ```R library(waffle) library(magrittr) library(hrbrthemes) library(ggplot2) library(dplyr) library(waffle) # current verison packageVersion("waffle") ## [1] '1.0.2' ``` -------------------------------- ### Preparing Data for Waffle and Pictogram Charts Source: https://github.com/hrbrmstr/waffle/blob/master/README.md This R code creates a data frame named `xdf` which will be used as input for subsequent waffle and pictogram chart examples. It contains columns for categorical parts, numerical values, colors, and a grouping factor, demonstrating how to structure data for these visualizations. ```R data.frame( parts = factor(rep(month.abb[1:3], 3), levels=month.abb[1:3]), vals = c(10, 20, 30, 6, 14, 40, 30, 20, 10), col = rep(c("navy", "black", "maroon"), 3), fct = c( rep("Thing 1", 3), rep("Thing 2", 3), rep("Thing 3", 3) ) ) -> xdf ``` -------------------------------- ### Creating a Pictogram Chart with geom_pictogram Source: https://github.com/hrbrmstr/waffle/blob/master/README.md This R code creates a pictogram chart using `geom_pictogram`. It maps `parts` to labels and `n` to values, using Font Awesome glyphs ('apple-alt', 'bread-slice', 'pizza-slice') for visualization. The chart is configured with 10 rows, flipped orientation, proportional scaling, custom colors, and enhanced with specific theme adjustments for the legend. ```R xdf %>% count(parts, wt = vals) %>% ggplot( aes(label = parts, values = n) ) + geom_pictogram( n_rows = 10, aes(colour = parts), flip = TRUE, make_proportional = TRUE ) + scale_color_manual( name = NULL, values = c("#a40000", "#c68958", "#ae6056"), labels = c("Fruit", "Sammich", "Pizza") ) + scale_label_pictogram( name = NULL, values = c("apple-alt", "bread-slice", "pizza-slice"), labels = c("Fruit", "Sammich", "Pizza") ) + coord_equal() + theme_ipsum_rc(grid="") + theme_enhance_waffle() + theme( legend.key.height = unit(2.25, "line"), legend.text = element_text(size = 10, hjust = 0, vjust = 0.75) ) ``` -------------------------------- ### Generating Package Code Metrics with cloc in R Source: https://github.com/hrbrmstr/waffle/blob/master/README.md This R code snippet utilizes the `cloc` package to generate and display markdown-formatted code metrics for the current R package. It's commonly used for project documentation to quantify lines of code, blank lines, and file counts across different programming languages within the package. ```R cloc::cloc_pkg_md() ``` -------------------------------- ### Advanced Pictogram Chart with Custom Font Awesome Brands Source: https://github.com/hrbrmstr/waffle/blob/master/README.md This R snippet demonstrates an advanced pictogram chart using `geom_pictogram` with custom Font Awesome 5 Brand glyphs. It visualizes data using 'bitbucket', 'github', and 'git-alt' icons, applying specific colors and labels. The chart is set up with 20 rows, a larger glyph size, flipped orientation, and custom legend text alignment. ```R xdf %>% count(parts, wt = vals) %>% ggplot( aes(label = parts, values = n) ) + geom_pictogram( n_rows = 20, size = 6, aes(colour = parts), flip = TRUE, family = "FontAwesome5Brands-Regular" ) + scale_color_manual( name = NULL, values = c("#073f9c", "black", "#f34323"), labels = c("BitBucket", "GitHub", "Other") ) + scale_label_pictogram( name = NULL, values = c("bitbucket", "github", "git-alt"), labels = c("BitBucket", "GitHub", "Other") ) + coord_equal() + theme_ipsum_rc(grid="") + theme_enhance_waffle() + theme( legend.text = element_text(hjust = 0, vjust = 1) ) ``` -------------------------------- ### Creating a Basic Waffle Chart with geom_waffle Source: https://github.com/hrbrmstr/waffle/blob/master/README.md This R snippet generates a waffle chart using `geom_waffle` from the 'waffle' package. It processes the `xdf` data, maps `parts` to fill color and `n` (counted values) to the waffle squares, and applies custom colors, a white border, and a flipped orientation. The plot is enhanced with a custom theme and equal coordinates. ```R xdf %>% count(parts, wt = vals) %>% ggplot( aes(fill = parts, values = n) ) + geom_waffle( n_rows = 20, size = 0.33, colour = "white", flip = TRUE ) + scale_fill_manual( name = NULL, values = c("#a40000", "#c68958", "#ae6056"), labels = c("Fruit", "Sammich", "Pizza") ) + coord_equal() + theme_ipsum_rc(grid="") + theme_enhance_waffle() ``` -------------------------------- ### Creating Faceted Waffle Charts Source: https://github.com/hrbrmstr/waffle/blob/master/README.md This R code generates multiple waffle charts arranged in facets, demonstrating the use of `facet_wrap` with `geom_waffle`. It creates a new tibble `xdf` with a grouping factor `fct`, then plots waffle charts for each facet, applying custom colors, white borders, and specific axis expansions for a clean layout. ```R library(hrbrthemes) library(waffle) library(tidyverse) tibble( parts = factor(rep(month.abb[1:3], 3), levels=month.abb[1:3]), values = c(10, 20, 30, 6, 14, 40, 30, 20, 10), fct = c(rep("Thing 1", 3), rep("Thing 2", 3), rep("Thing 3", 3)) ) -> xdf ggplot( data = xdf, aes(fill=parts, values=values) ) + geom_waffle( color = "white", size = 1.125, n_rows = 6 ) + facet_wrap(~fct, ncol=1) + scale_x_discrete( expand = c(0,0,0,0) ) + scale_ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.