### Install hrbrthemes Package Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/index.html Install the hrbrthemes package from GitHub using devtools. ```r devtools::install_github("hrbrmstr/hrbrthemes") ``` -------------------------------- ### Flexoki Light Discrete Color Scale Example Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/README.md Demonstrates the use of the Flexoki light discrete color scale with ggplot2. Ensure the hrbrthemes package is installed and loaded. ```r ggplot(mpg, aes(class, fill=class)) + geom_bar() + labs(title="Flexoki Light Colors", subtitle="Discrete color scale example", caption="Using scale_fill_flexoki_light()") + theme_ipsum() + scale_fill_flexoki_light() + theme(legend.position="none") ``` -------------------------------- ### Install hrbrthemes Package Source: https://context7.com/hrbrmstr/hrbrthemes/llms.txt Installs the hrbrthemes package from CRAN or the latest version from Codeberg. Also loads the library and checks the package version. ```r install.packages("hrbrthemes") # Latest from Codeberg (0.9.2) remotes::install_git("https://codeberg.org/hrbrmstr/hrbrthemes.git") library(hrbrthemes) packageVersion("hrbrthemes") ## [1] '0.9.2' ``` -------------------------------- ### Install hrbrthemes Package Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/README.md Install the hrbrthemes package from CRAN or directly from its Git repository using the remotes package. ```r install.packages("hrbrthemes") # NOTE: CRAN version is 0.8.7 # or remotes::install_git("https://codeberg.org/hrbrmstr/hrbrthemes.git") ``` -------------------------------- ### Load Fonts and Create Scatterplot with theme_ipsum_tw Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/theme_ipsum_tw.html Example of loading necessary libraries and applying the theme_ipsum_tw to a ggplot2 scatterplot. This demonstrates basic plot customization with the theme. ```R library(ggplot2) library(dplyr) # seminal scatterplot ggplot(mtcars, aes(mpg, wt)) + geom_point() + labs(x="Fuel effiiency (mpg)", y="Weight (tons)", title="Seminal ggplot2 scatterplot example", subtitle="A plot that is only useful for demonstration purposes", caption="Brought to you by the letter 'g'") + theme_ipsum_rc() # Note: The example uses theme_ipsum_rc, but the context is theme_ipsum_tw. Assuming this is a typo in the source and it should be theme_ipsum_tw() ``` -------------------------------- ### Flexoki Dark Discrete Color Scale Example Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/README.md Illustrates the Flexoki dark discrete color scale for scatter plots using ggplot2. This example uses theme_ipsum_rc() for a different aesthetic. ```r ggplot(mpg, aes(displ, hwy, color=class)) + geom_point(size=3) + labs(title="Flexoki Dark Colors", subtitle="Another discrete color example", caption="Using scale_color_flexoki_dark()") + theme_ipsum_rc() + scale_color_flexoki_dark() ``` -------------------------------- ### Create Bar Chart with theme_ipsum_tw Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/theme_ipsum_tw.html Example of creating a bar chart using ggplot2 and applying theme customizations. It includes adding text labels to the bars. ```R count(mpg, class) %>% ggplot(aes(class, n)) + geom_col() + geom_text(aes(label=n), nudge_y=3) + ``` -------------------------------- ### New FT Theme Example Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/index.html Apply the new FT theme with custom colors to a ggplot2 scatterplot. ```r ggplot(mtcars, aes(mpg, wt)) + geom_point(color = ft_cols$yellow) + labs(x="Fuel efficiency (mpg)", y="Weight (tons)", title="Seminal ggplot2 scatterplot example", subtitle="A plot that is only useful for demonstration purposes", caption="Brought to you by the letter 'g'") + theme_ft_rc() ``` -------------------------------- ### Color/Fill Scales Example Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/index.html Demonstrates the use of custom color and fill scales from hrbrthemes on a ggplot2 scatterplot. ```r ggplot(mtcars, aes(mpg, wt)) + geom_point(aes(color=factor(carb))) + labs(x="Fuel efficiency (mpg)", y="Weight (tons)", title="Seminal ggplot2 scatterplot example", subtitle="A plot that is only useful for demonstration purposes", caption="Brought to you by the letter 'g'") + scale_color_ipsum() + theme_ipsum_rc() ``` -------------------------------- ### Apply theme_ipsum to a ggplot Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/theme_ipsum.html Demonstrates how to apply the theme_ipsum theme to a ggplot object. This example also shows how to customize grid lines and remove y-axis text. ```R library(dplyr) library(ggplot2) library(hrbrthemes) mpg %>% count(class) %>% ggplot(aes(class, n)) + geom_col() + geom_text(aes(label=n), nudge_y=3) + labs(x="Fuel efficiency (mpg)", y="Weight (tons)", title="Seminal ggplot2 bar chart example", subtitle="A plot that is only useful for demonstration purposes", caption="Brought to you by the letter 'g'") + theme_ipsum(grid="Y") + theme(axis.text.y=element_blank()) ``` -------------------------------- ### Titillium Web Theme Example Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/index.html Apply the Titillium Web theme with custom scales and facets to a ggplot2 plot. ```r ggplot(mpg, aes(displ, hwy)) + geom_jitter(aes(color=class, fill=class), size=3, shape=21, alpha=1/2) + scale_x_continuous(expand=c(0,0), limits=c(1, 8), breaks=1:8) + scale_y_continuous(expand=c(0,0), limits=c(10, 50)) + scale_color_ipsum() + scale_fill_ipsum() + facet_wrap(~class, scales="free") + labs( title="Titillium Web", subtitle="This is a subtitle to see the how it looks in Titillium Web", caption="Source: hrbrthemes & Google" ) + theme_ipsum_tw(grid="XY", axis="xy") + theme(legend.position="none") -> gg flush_ticks(gg) ``` -------------------------------- ### Roboto Condensed Theme Example Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/index.html Apply the Roboto Condensed theme to a ggplot2 scatterplot. ```r ggplot(mtcars, aes(mpg, wt)) + geom_point() + labs(x="Fuel efficiency (mpg)", y="Weight (tons)", title="Seminal ggplot2 scatterplot example", subtitle="A plot that is only useful for demonstration purposes", caption="Brought to you by the letter 'g'") + theme_ipsum_rc() ``` -------------------------------- ### IBM Plex Sans Theme Example Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/index.html Apply the IBM Plex Sans theme with custom scales and facets to a ggplot2 plot. ```r ggplot(mpg, aes(displ, hwy)) + geom_jitter(aes(color=class, fill=class), size=3, shape=21, alpha=1/2) + scale_x_continuous(expand=c(0,0), limits=c(1, 8), breaks=1:8) + scale_y_continuous(expand=c(0,0), limits=c(10, 50)) + scale_color_ipsum() + scale_fill_ipsum() + facet_wrap(~class, scales="free") + labs( title="IBM Plex Sans Test", subtitle="This is a subtitle to see the how it looks in IBM Plex Sans", caption="Source: hrbrthemes & IBM" ) + theme_ipsum_ps(grid="XY", axis="xy") + theme(legend.position="none") -> gg flush_ticks(gg) ``` -------------------------------- ### Bit12 Continuous Color Scales Visualization Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/README.md Visualizes selected continuous color palettes from the Bit12 system using ggplot2 and patchwork. This example demonstrates applying specific palettes to a gradient. ```r library(patchwork) # Taking a subset of the palette for this example names(bit12)[c(1,3,5,7,9,11)] |> map(\(.p) { ggplot(grad_df, aes(x, y, fill=z)) + geom_tile() + scale_fill_bit12_continuous(palette = .p) + labs( x = NULL, y = NULL, title = .p ) + theme_ipsum(grid="") + theme(legend.position = "none") }) |> do.call(what = "wrap_plots") + plot_layout(ncol = 3) + plot_annotation( title="Bit12 Continuous Color Scales", subtitle="Selected continuous color palettes", caption="Using scale_fill_bit12_continuous()", theme = theme_ipsum(grid="") ) ``` -------------------------------- ### Apply theme_ipsum_rc to a ggplot2 scatterplot Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/theme_ipsum_rc.html This example demonstrates how to apply the theme_ipsum_rc theme to a basic ggplot2 scatterplot. Ensure the necessary libraries (ggplot2, dplyr) are loaded. ```R library(ggplot2) library(dplyr) # seminal scatterplot ggplot(mtcars, aes(mpg, wt)) + geom_point() + labs(x="Fuel effiiency (mpg)", y="Weight (tons)", title="Seminal ggplot2 scatterplot example", subtitle="A plot that is only useful for demonstration purposes", caption="Brought to you by the letter 'g'") + theme_ipsum_rc() ``` -------------------------------- ### Import Fonts for R Graphics Devices Source: https://context7.com/hrbrmstr/hrbrthemes/llms.txt Imports bundled or system fonts for use in R graphics devices. Registers the font path; system-wide installation may be needed for PDF/PostScript output. Provides variables for font names and an option to auto-load fonts for PDF/PostScript. ```r library(hrbrthemes) # Import Roboto Condensed (bundled with the package) import_roboto_condensed() # Import IBM Plex Sans (bundled with the package) import_plex_sans() # Import Econ Sans Condensed (must be installed separately) import_econ_sans() ``` ```r # Font name variables — use these instead of raw strings font_an # "Arial Narrow" font_rc # "Roboto Condensed" font_rc_light # "Roboto Condensed Light" (not available on Windows) font_ps # "IBM Plex Sans" font_ps_light # "IBM Plex Sans Light" font_pub # "Public Sans" font_pub_bold # "Public Sans Bold" font_pub_light # "Public Sans Light" font_pub_thin # "Public Sans Thin" font_es # "Econ Sans Condensed" font_es_bold # "Econ Sans Condensed Bold" font_es_light # "Econ Sans Condensed Light" ``` ```r # Option to auto-load fonts for PDF/PostScript options(hrbrthemes.loadfonts = TRUE) ``` -------------------------------- ### Base Theme (Arial Narrow) Example Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/index.html Apply the base hrbrthemes theme (Arial Narrow) to a ggplot2 scatterplot. ```r ggplot(mtcars, aes(mpg, wt)) + geom_point() + labs(x="Fuel efficiency (mpg)", y="Weight (tons)", title="Seminal ggplot2 scatterplot example", subtitle="A plot that is only useful for demonstration purposes", caption="Brought to you by the letter 'g'") + theme_ipsum() ``` -------------------------------- ### theme_ipsum_tw Function Definition Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/theme_ipsum_tw.html This is the function definition for theme_ipsum_tw, outlining its parameters for customizing plot elements like fonts, sizes, and margins. Ensure Titillium Web fonts are installed and loaded. ```R theme_ipsum_tw(base_family = "Titillium Web", base_size = 10.5, plot_title_family = if (.Platform$OS.type == "windows") "Titillium Web" else "Titillium Web Bold", plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = if (.Platform$OS.type == "windows") "Titillium Web" else "Titillium Web Light", subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip_text_family = base_family, strip_text_size = 12, strip_text_face = "plain", caption_family = if (.Platform$OS.type == "windows") "Titillium Web" else "Titillium Web Light", caption_size = 9, caption_face = "plain", caption_margin = 10, axis_text_size = base_size, axis_title_family = base_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", plot_margin = margin(30, 30, 30, 30), grid_col = "#cccccc", grid = TRUE, axis_col = "#cccccc", axis = FALSE, ticks = FALSE) ``` -------------------------------- ### Import IBM Plex Sans Font Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/import_plex_sans.html This function imports the IBM Plex Sans font for use in charts. It also handles the registration of non-core fonts with R's graphics devices, particularly for PDF and PostScript output, and provides guidance on system-level font installation. ```APIDOC ## import_plex_sans() ### Description Imports the IBM Plex Sans font for use in charts. This function also manages the registration of non-core fonts with R's graphics devices (PDF/PostScript) and provides information on system-level font installation. ### Details There is an option `hrbrthemes.loadfonts` which -- if set to `TRUE` -- will call `[extrafont::loadfonts()](https://www.rdocumentation.org/packages/extrafont/topics/loadfonts)` to register non-core fonts with R PDF & PostScript devices. If you are running under Windows, the package calls the same function to register non-core fonts with the Windows graphics device. ### Note This will take care of ensuring PDF/PostScript usage. The location of the font directory is displayed after the base import is complete. It is highly recommended that you install them on your system the same way you would any other font you wish to use in other programs. ``` -------------------------------- ### Create ggplot2 Column Chart with Comma Labels and Flipped Coordinates Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/index.html This example demonstrates using `geom_text()` with `scales::comma()` for formatted labels and `coord_flip()` to reverse axis orientation. `scale_y_comma()` ensures the y-axis also uses comma formatting. ```R update_geom_font_defaults(font_rc_light) count(mpg, class) %>% mutate(n=n*2000) %>% arrange(n) %>% mutate(class=factor(class, levels=class)) %>% ggplot(aes(class, n)) + geom_col() + geom_text(aes(label=scales::comma(n)), hjust=0, nudge_y=2000) + scale_y_comma(limits=c(0,150000)) + coord_flip() + labs(x="Fuel efficiency (mpg)", y="Weight (tons)", title="Seminal ggplot2 column chart example with commas", subtitle="A plot that is only useful for demonstration purposes, esp since you'd never\nreally want direct labels and axis labels", caption="Brought to you by the letter 'g'") + theme_ipsum_rc(grid="X") ``` -------------------------------- ### theme_ipsum_ps Function Signature Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/theme_ipsum_ps.html This is the function signature for theme_ipsum_ps, detailing all customizable arguments for plot title, subtitle, strip text, caption, axis text, and plot margins. Ensure IBM Plex Sans fonts are installed and imported before use. ```R theme_ipsum_ps(base_family = "IBMPlexSans", base_size = 11.5, plot_title_family = "IBMPlexSans-Bold", plot_title_size = 18, plot_title_face = "plain", plot_title_margin = 10, subtitle_family = if (.Platform$OS.type == "windows") "IBMPlexSans" else "IBMPlexSans-Light", subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip_text_family = "IBMPlexSans-Medium", strip_text_size = 12, strip_text_face = "plain", caption_family = if (.Platform$OS.type == "windows") "IBMPlexSans" else "IBMPlexSans-Thin", caption_size = 9, caption_face = "plain", caption_margin = 10, axis_text_size = 9, axis_title_family = base_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", plot_margin = margin(30, 30, 30, 30), grid_col = "#cccccc", grid = TRUE, axis_col = "#cccccc", axis = FALSE, ticks = FALSE) ``` -------------------------------- ### Apply theme_ipsum_rc to a ggplot2 bar chart Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/theme_ipsum_rc.html This example shows how to apply the theme_ipsum_rc theme to a ggplot2 bar chart. It includes setting font defaults for Windows and customizing axis text. The update_geom_font_defaults function is used to ensure the correct font is applied. ```R # note: make this font_rc on Windows update_geom_font_defaults(family=font_rc_light) count(mpg, class) %>% ggplot(aes(class, n)) + geom_col() + geom_text(aes(label=n), nudge_y=3) + labs(x="Fuel effiiency (mpg)", y="Weight (tons)", title="Seminal ggplot2 bar chart example", subtitle="A plot that is only useful for demonstration purposes", caption="Brought to you by the letter 'g'") + theme_ipsum_rc(grid="Y") + theme(axis.text.y = element_blank()) ``` -------------------------------- ### Load Libraries and Check Version Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/index.html Load necessary libraries and check the current version of the hrbrthemes package. ```r library(hrbrthemes) library(gcookbook) library(tidyverse) # current verison packageVersion("hrbrthemes") ``` -------------------------------- ### Basic Scatterplot with theme_ipsum Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/theme_ipsum.html Demonstrates how to apply the theme_ipsum to a ggplot2 scatterplot. Ensure ggplot2 and dplyr libraries are loaded. ```R library(ggplot2) library(dplyr) # seminal scatterplot ggplot(mtcars, aes(mpg, wt)) + geom_point() + labs(x="Fuel effiiency (mpg)", y="Weight (tons)", title="Seminal ggplot2 scatterplot example", subtitle="A plot that is only useful for demonstration purposes", caption="Brought to you by the letter 'g'") + theme_ipsum() ``` -------------------------------- ### scale_x_percent Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/scale_x_percent.html Creates an X-axis scale with percentage formatting. It sets the axis text to a percentage format and uses expand=c(0,0), requiring limits to be set. ```APIDOC ## scale_x_percent ### Description Creates an X-axis scale with percentage formatting. It sets the axis text to a percentage format and uses expand=c(0,0), requiring limits to be set. ### Arguments * **name** (waiver() or NULL) - The name of the scale, used as axis or legend title. * **breaks** (NULL, waiver(), numeric vector, or function) - Positions for major breaks. * **minor_breaks** (NULL, waiver(), numeric vector, or function) - Positions for minor breaks. * **labels** (NULL, waiver(), character vector, or function) - Labels for the breaks. * **limits** (numeric vector) - A numeric vector of length two providing limits of the scale. * **expand** (c(0.01, 0)) - Expansion factor for the scale. * **oob** (censor) - Function that handles limits outside of the scale limits. * **na.value** (NA_real_) - Value aesthetic for missing data. * **trans** ("identity") - Transformation object for the scale. * **position** ("bottom") - The position of the axis. * **sec.axis** (waiver()) - Specify a secondary axis. ``` -------------------------------- ### Show ipsum_pal() colors Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/ipsum_pal.html Loads the scales package and displays the first 9 colors from the ipsum_pal() palette. ```r library(scales) scales::show_col(ipsum_pal()(9)) ``` -------------------------------- ### Bar Chart with theme_ipsum_rc and Font Updates Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/theme_ipsum_ps.html Demonstrates creating a bar chart with geom_col and geom_text for labels, using theme_ipsum_rc. It includes updating geom font defaults for light font variants on Windows. ```R # seminal bar chart # note: make this font_rc on Windows update_geom_font_defaults(family=font_rc_light) count(mpg, class) %>% ggplot(aes(class, n)) + geom_col() + geom_text(aes(label=n), nudge_y=3) + labs(x="Fuel effiiency (mpg)", y="Weight (tons)", ``` -------------------------------- ### theme_ipsum_tw Function Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/theme_ipsum_tw.html Applies the theme_ipsum_tw theme to a ggplot object. It requires the Titillium Web font to be installed and optionally loads fonts using extrafont. ```APIDOC ## theme_ipsum_tw ### Description Applies the theme_ipsum_tw theme to a ggplot object. This theme is precise and pristine, with opinionated defaults and an emphasis on typography, using the Titillium Web font. ### Arguments * **base_family** (string) - Base font family. Defaults to "Titillium Web". * **base_size** (numeric) - Base font size. Defaults to 10.5. * **plot_title_family** (string) - Font family for the plot title. Defaults to "Titillium Web" on Windows, "Titillium Web Bold" otherwise. * **plot_title_size** (numeric) - Font size for the plot title. Defaults to 18. * **plot_title_face** (string) - Font face for the plot title. Defaults to "bold". * **plot_title_margin** (numeric) - Margin for the plot title. Defaults to 10. * **subtitle_family** (string) - Font family for the subtitle. Defaults to "Titillium Web" on Windows, "Titillium Web Light" otherwise. * **subtitle_size** (numeric) - Font size for the subtitle. Defaults to 13. * **subtitle_face** (string) - Font face for the subtitle. Defaults to "plain". * **subtitle_margin** (numeric) - Margin for the subtitle. Defaults to 15. * **strip_text_family** (string) - Font family for facet labels. Defaults to `base_family`. * **strip_text_size** (numeric) - Font size for facet labels. Defaults to 12. * **strip_text_face** (string) - Font face for facet labels. Defaults to "plain". * **caption_family** (string) - Font family for the caption. Defaults to "Titillium Web" on Windows, "Titillium Web Light" otherwise. * **caption_size** (numeric) - Font size for the caption. Defaults to 9. * **caption_face** (string) - Font face for the caption. Defaults to "plain". * **caption_margin** (numeric) - Margin for the caption. Defaults to 10. * **axis_text_size** (numeric) - Font size for axis text. Defaults to `base_size`. * **axis_title_family** (string) - Font family for axis titles. Defaults to `base_family`. * **axis_title_size** (numeric) - Font size for axis titles. Defaults to 9. * **axis_title_face** (string) - Font face for axis titles. Defaults to "plain". * **axis_title_just** (string) - Justification for axis titles. One of `[blmcrt]`. Defaults to "rt". * **plot_margin** (numeric) - Plot margin. Specified with `ggplot2::margin()`. Defaults to `margin(30, 30, 30, 30)`. * **grid_col** (string) - Color of the grid lines. Defaults to "#cccccc". * **grid** (boolean or string) - Whether to display grid lines. Can be `TRUE`, `FALSE`, or a combination of `X`, `x`, `Y`, `y`. Defaults to `TRUE`. * **axis_col** (string) - Color of the axis lines. Defaults to "#cccccc". * **axis** (boolean or string) - Whether to display axes. Can be `TRUE`, `FALSE`, or "xy". Defaults to `FALSE`. * **ticks** (boolean) - Whether to display ticks. Defaults to `FALSE`. ### Details It is recommended to import Titillium Web fonts and install them on your system before using this theme. An option `hrbrthemes.loadfonts` can be set to `TRUE` to call `extrafont::loadfonts()` for registering non-core fonts with R graphics devices. ``` -------------------------------- ### Flexoki Continuous Color Scales Visualization Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/README.md Generates a visualization of all 8 continuous Flexoki color palettes using ggplot2, patchwork, and geom_tile. Requires the 'patchwork' library. ```r library(patchwork) data.frame( x = rep(1:50, 50), y = rep(1:50, each=50), z = sqrt((rep(1:50, 50)-25)^2 + (rep(1:50, each=50)-25)^2) ) -> grad_df names(flexoki_dark) |> map(\(.p) { ggplot(grad_df, aes(x, y, fill=z)) + geom_tile() + scale_fill_flexoki_continuous(palette = .p) + labs( x = NULL, y = NULL ) + theme_ipsum(grid="") + theme(legend.position = "none") }) |> do.call(what = "wrap_plots") + plot_layout(ncol = 4) + plot_annotation( title="Flexoki Continuous Color Scales", subtitle="All 8 continuous color palettes", caption="Using scale_fill_flexoki_continuous()", theme = theme_ipsum(grid="") ) ``` -------------------------------- ### Show ft_pal() colors Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/ft_pal.html Demonstrates how to display the colors generated by the ft_pal() function using the scales::show_col() function. Ensure the scales package is loaded. ```R library(scales) scales::show_col(ft_pal()(8)) ``` -------------------------------- ### theme_ipsum_rc Function Definition Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/theme_ipsum_rc.html Defines the theme_ipsum_rc function, which sets a ggplot2 theme with customizable typographic elements. Ensure Roboto Condensed font is installed and imported before use. ```R theme_ipsum_rc(base_family = "Roboto Condensed", base_size = 11.5, plot_title_family = base_family, plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = if (.Platform$OS.type == "windows") "Roboto Condensed" else "Roboto Condensed Light", subtitle_size = 13, subtitle_face = "plain", subtitle_margin = 15, strip_text_family = base_family, strip_text_size = 12, strip_text_face = "plain", caption_family = if (.Platform$OS.type == "windows") "Roboto Condensed" else "Roboto Condensed Light", caption_size = 9, caption_face = "plain", caption_margin = 10, axis_text_size = base_size, axis_title_family = base_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", plot_margin = margin(30, 30, 30, 30), grid_col = "#cccccc", grid = TRUE, axis_col = "#cccccc", axis = FALSE, ticks = FALSE) ``` -------------------------------- ### Other Light Themes with Different Fonts Source: https://context7.com/hrbrmstr/hrbrthemes/llms.txt Demonstrates alternative light themes using different default fonts: Goldman Sans Condensed, Public Sans, and Titillium Web. These themes follow the same parameter interface as `theme_ipsum()`. ```r library(ggplot2) library(hrbrthemes) # Goldman Sans Condensed p1 <- ggplot(mtcars, aes(mpg, wt)) + geom_point() + labs(title = "Goldman Sans", caption = "theme_ipsum_gs()") + theme_ipsum_gs() # Public Sans p2 <- ggplot(mtcars, aes(mpg, wt)) + geom_point() + labs(title = "Public Sans", caption = "theme_ipsum_pub()") + theme_ipsum_pub() # Titillium Web p3 <- ggplot(mtcars, aes(mpg, wt)) + geom_point() + labs(title = "Titillium Web", caption = "theme_ipsum_tw()") + theme_ipsum_tw() ``` -------------------------------- ### ipsum_pal() Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/ipsum_pal.html Generates a muted, qualitative color palette. ```APIDOC ## ipsum_pal() ### Description A muted, qualitative color palette. ### Usage ipsum_pal() ### Examples ```R library(scales) scales::show_col(ipsum_pal()(9)) ``` ``` -------------------------------- ### Bit12 Discrete Color Scale Example Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/README.md Applies the Bit12 discrete color scale to a bar chart using ggplot2. This palette offers 12 distinct colors suitable for categorical data. ```r ggplot(mpg, aes(class, fill=class)) + geom_bar() + labs(title="Bit12 Color Palette", subtitle="A vibrant 12-color categorical palette", caption="Using scale_fill_bit12()") + theme_ipsum() + scale_fill_bit12() + theme(legend.position="none") ``` -------------------------------- ### Load hrbrthemes and Dependencies Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/README.md Load the hrbrthemes package along with gcookbook and tidyverse for data manipulation and plotting. ```r library(hrbrthemes) library(gcookbook) library(tidyverse) # current version packageVersion("hrbrthemes") ## [1] '0.9.2' ``` -------------------------------- ### Apply theme_ipsum_rc() with Roboto Condensed Source: https://context7.com/hrbrmstr/hrbrthemes/llms.txt Applies the Roboto Condensed theme to a bar chart. Requires importing the font and updating geom defaults. Supports selective grid lines. ```r library(ggplot2) library(dplyr) library(hrbrthemes) import_roboto_condensed() update_geom_font_defaults(family = font_rc_light) count(mpg, class) %>% ggplot(aes(class, n)) + geom_col() + geom_text(aes(label = n), nudge_y = 3) + labs( x = "Vehicle class", y = "Count", title = "Vehicle class distribution", subtitle = "mpg dataset", caption = "Source: ggplot2" ) + theme_ipsum_rc(grid = "Y") + theme(axis.text.y = element_blank()) ``` -------------------------------- ### ft_pal() Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/ft_pal.html Generates a bright qualitative color palette. ```APIDOC ## ft_pal() ### Description A bright qualitative color palette. ### Usage ft_pal() ### Examples ```R library(scales) scales::show_col(ft_pal()(8)) ``` ![ft_pal example](ft_pal-1.png) ``` -------------------------------- ### scale_color_ipsum Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/scale_ipsum.html Creates a discrete color scale using the ipsum palette. This is an alias for `scale_colour_ipsum`. ```APIDOC ## scale_color_ipsum ### Description Creates a discrete color scale using the ipsum palette. This is an alias for `scale_colour_ipsum`. ### Arguments See `scale_colour_ipsum` for a full list of arguments. ``` -------------------------------- ### scale_x_comma Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/scale_x_percent.html Creates an X-axis scale with comma formatting for axis text and uses expand=c(0,0), requiring limits to be set. ```APIDOC ## scale_x_comma ### Description Creates an X-axis scale with comma formatting for axis text and uses expand=c(0,0), requiring limits to be set. ### Arguments * **name** (waiver() or NULL) - The name of the scale, used as axis or legend title. * **breaks** (NULL, waiver(), numeric vector, or function) - Positions for major breaks. * **minor_breaks** (NULL, waiver(), numeric vector, or function) - Positions for minor breaks. * **labels** (NULL, waiver(), character vector, or function) - Labels for the breaks. * **limits** (numeric vector) - A numeric vector of length two providing limits of the scale. * **expand** (c(0.01, 0)) - Expansion factor for the scale. * **oob** (censor) - Function that handles limits outside of the scale limits. * **na.value** (NA_real_) - Value aesthetic for missing data. * **trans** ("identity") - Transformation object for the scale. * **position** ("bottom") - The position of the axis. * **sec.axis** (waiver()) - Specify a secondary axis. ``` -------------------------------- ### Apply theme_ft_rc() Dark FT-style Theme Source: https://context7.com/hrbrmstr/hrbrthemes/llms.txt Applies a dark Financial Times-style theme using Roboto Condensed. Updates geom defaults for the FT dark theme and uses a specific color from the ft_cols palette. ```r library(ggplot2) library(hrbrthemes) ft_geom_defaults() # update all geom defaults for the FT dark theme ggplot(mtcars, aes(mpg, wt)) + geom_point(color = ft_cols$yellow) + labs( x = "Fuel efficiency (mpg)", y = "Weight (tons)", title = "FT Dark Theme Example", subtitle = "Yellow point color from ft_cols palette", caption = "Brought to you by the letter 'g'" ) + theme_ft_rc() # Background: #252a32 | Grid: #464950 | Title: #ffffff ``` -------------------------------- ### scale_y_percent Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/scale_x_percent.html Creates a Y-axis scale with percentage formatting. Similar to scale_x_percent but for the Y-axis. ```APIDOC ## scale_y_percent ### Description Creates a Y-axis scale with percentage formatting. Similar to scale_x_percent but for the Y-axis. ### Arguments * **name** (waiver() or NULL) - The name of the scale, used as axis or legend title. * **breaks** (NULL, waiver(), numeric vector, or function) - Positions for major breaks. * **minor_breaks** (NULL, waiver(), numeric vector, or function) - Positions for minor breaks. * **labels** (NULL, waiver(), character vector, or function) - Labels for the breaks. * **limits** (numeric vector) - A numeric vector of length two providing limits of the scale. * **expand** (c(0.01, 0)) - Expansion factor for the scale. * **oob** (censor) - Function that handles limits outside of the scale limits. * **na.value** (NA_real_) - Value aesthetic for missing data. * **trans** ("identity") - Transformation object for the scale. * **position** ("left") - The position of the axis. * **sec.axis** (waiver()) - Specify a secondary axis. ``` -------------------------------- ### Scale Functions Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/index.html Functions to create custom color and fill scales. ```APIDOC ## Scale Functions ### Description Creates custom discrete color and fill scales for plots. ### Functions - `scale_colour_ft()` / `scale_color_ft()` / `scale_fill_ft()`: Discrete color & fill scales based on the FT palette. - `scale_colour_ipsum()` / `scale_color_ipsum()` / `scale_fill_ipsum()`: Discrete color & fill scales based on the ipsum palette. ``` -------------------------------- ### R Markdown Templates Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/index.html Functions for generating R Markdown content. ```APIDOC ## R Markdown Template Functions ### Description Provides functions to generate R Markdown content with specific formatting. ### Functions - `ipsum()`: R Markdown template. - `ipsum_pdf()`: R Markdown template for PDF output. ``` -------------------------------- ### theme_ipsum Function Signature Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/theme_ipsum.html This is the function signature for theme_ipsum, detailing all available arguments for customization. It allows control over font families, sizes, faces, margins, colors, and grid/axis properties. ```R theme_ipsum(base_family = "Arial Narrow", base_size = 11.5, plot_title_family = base_family, plot_title_size = 18, plot_title_face = "bold", plot_title_margin = 10, subtitle_family = base_family, subtitle_size = 12, subtitle_face = "plain", subtitle_margin = 15, strip_text_family = base_family, strip_text_size = 12, strip_text_face = "plain", caption_family = base_family, caption_size = 9, caption_face = "italic", caption_margin = 10, axis_text_size = base_size, axis_title_family = subtitle_family, axis_title_size = 9, axis_title_face = "plain", axis_title_just = "rt", plot_margin = margin(30, 30, 30, 30), grid_col = "#cccccc", grid = TRUE, axis_col = "#cccccc", axis = FALSE, ticks = FALSE) ``` -------------------------------- ### Apply theme_modern_rc() Dark RStudio-style Theme Source: https://context7.com/hrbrmstr/hrbrthemes/llms.txt Applies a dark RStudio-style theme with a very dark background. Updates geom defaults to a sky-blue foreground and supports similar parameters to theme_ipsum_rc(). ```r library(ggplot2) library(hrbrthemes) modern_geom_defaults() # set all geom colours to white for dark bg ggplot(mtcars, aes(factor(cyl), fill = factor(cyl))) + geom_bar() + labs( title = "Cylinder distribution", caption = "theme_modern_rc example" ) + theme_modern_rc(grid = "Y") + theme(legend.position = "none") ``` -------------------------------- ### Create ggplot2 Area Chart with Custom Scales and Theme Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/index.html Utilize `scale_fill_ipsum()` for custom fill colors and `scale_y_comma()` for comma-formatted y-axis labels. `theme_ipsum_rc()` applies a specific theme with grid lines. ```R ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup)) + geom_area() + scale_fill_ipsum() + scale_x_continuous(expand=c(0,0)) + scale_y_comma() + labs(title="Age distribution of population in the U.S., 1900-2002", subtitle="Example data from the R Graphics Cookbook", caption="Source: R Graphics Cookbook") + theme_ipsum_rc(grid="XY") + theme(axis.text.x=element_text(hjust=c(0, 0.5, 0.5, 0.5, 1))) + theme(legend.position="bottom") ``` -------------------------------- ### Axis Scale Presets Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/index.html Functions to apply opinionated pre-sets for axis labels. ```APIDOC ## Axis Scale Presets ### Description Applies opinionated pre-sets for axis labels, particularly for percentage and comma formats. ### Functions - `scale_x_percent()` / `scale_y_percent()`: X & Y scales with opinionated pre-sets for percent label formats. - `scale_x_comma()` / `scale_y_comma()`: X & Y scales with opinionated pre-sets for comma label formats. ``` -------------------------------- ### Apply IBM Plex Sans Theme and Scales Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/README.md Applies the IBM Plex Sans theme and custom color/fill scales to a ggplot2 jitter plot with facets. Requires hrbrthemes. ```r ggplot(mpg, aes(displ, hwy)) + geom_jitter(aes(color=class, fill=class), size=3, shape=21, alpha=1/2) + scale_x_continuous(expand=c(0,0), limits=c(1, 8), breaks=1:8) + scale_y_continuous(expand=c(0,0), limits=c(10, 50)) + scale_color_ipsum() + scale_fill_ipsum() + facet_wrap(~class, scales="free") + labs( title="IBM Plex Sans Test", subtitle="This is a subtitle to see the how it looks in IBM Plex Sans", caption="Source: hrbrthemes & IBM" ) + theme_ipsum_ps(grid="XY", axis="xy") + theme(legend.position="none") -> gg flush_ticks(gg) ## theme(axis.text.x=element_text(hjust=c(0, rep(0.5, 6), 1))) + ## theme(axis.text.y=element_text(vjust=c(0, rep(0.5, 3), 1))) ``` -------------------------------- ### Color Palette Functions Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/index.html Functions for accessing and utilizing color palettes from hrbrthemes. ```APIDOC ## Color Palette Functions ### Description Provides access to predefined color palettes for use in visualizations. ### Functions - `ft_cols()` / `ft_text_col()`: Accesses the FT color palette. - `ft_pal()`: Generates a bright qualitative color palette. - `ipsum_pal()`: Generates a muted, qualitative color palette. ``` -------------------------------- ### scale_y_comma Source: https://github.com/hrbrmstr/hrbrthemes/blob/master/docs/reference/scale_x_percent.html Creates a Y-axis scale with comma formatting for axis text and uses expand=c(0,0), requiring limits to be set. ```APIDOC ## scale_y_comma ### Description Creates a Y-axis scale with comma formatting for axis text and uses expand=c(0,0), requiring limits to be set. ### Arguments * **name** (waiver() or NULL) - The name of the scale, used as axis or legend title. * **breaks** (NULL, waiver(), numeric vector, or function) - Positions for major breaks. * **minor_breaks** (NULL, waiver(), numeric vector, or function) - Positions for minor breaks. * **labels** (NULL, waiver(), character vector, or function) - Labels for the breaks. * **limits** (numeric vector) - A numeric vector of length two providing limits of the scale. * **expand** (c(0.01, 0)) - Expansion factor for the scale. * **oob** (censor) - Function that handles limits outside of the scale limits. * **na.value** (NA_real_) - Value aesthetic for missing data. * **trans** ("identity") - Transformation object for the scale. * **position** ("left") - The position of the axis. * **sec.axis** (waiver()) - Specify a secondary axis. ```