library(tidyverse) # Sine qua non
library(mosaic) # Out all-in-one package
library(ggformula) # Graphing package
library(skimr) # Looking at Data
library(janitor) # Clean the data
library(naniar) # Handle missing data
library(visdat) # Visualise missing data
##
library(ggcompare) # Comparing means across groups
library(ggstatsplot) # Graphs with statistical details
library(ggdist) # Visualizations of Distributions and Uncertainty
# devtools::install_github("wilkelab/ungeviz")
library(ungeviz) # Visualizing Uncertainty in Data
##
library(tinytable) # Printing Static Tables for our data
library(DT) # Interactive Tables for our data
library(crosstable) # Multiple variable summaries
##
library(marquee) # For Annotations with Fonts
library(ggrepel) # Repel overlapping text labels in ggplot2
Uncertainty
Abstract
In this module, we will explore the concept of uncertainty in data analysis. We will discuss different types of uncertainty, methods to quantify it, and how to communicate uncertainty effectively in our findings.
“Wrongs are often forgiven, but contempt never is. Our pride remembers it forever.”
— Lord Chesterfield, statesman and writer (22 Sep 1694-1773)
1 Setting up R Packages
Plot Fonts and Theme
Show the Code
library(systemfonts)
library(showtext)
## Clean the slate
systemfonts::clear_local_fonts()
systemfonts::clear_registry()
##
showtext_opts(dpi = 96) # set DPI for showtext
sysfonts::font_add(
family = "Alegreya",
regular = "../../../../../../fonts/Alegreya-Regular.ttf",
bold = "../../../../../../fonts/Alegreya-Bold.ttf",
italic = "../../../../../../fonts/Alegreya-Italic.ttf",
bolditalic = "../../../../../../fonts/Alegreya-BoldItalic.ttf"
)
sysfonts::font_add(
family = "Roboto Condensed",
regular = "../../../../../../fonts/RobotoCondensed-Regular.ttf",
bold = "../../../../../../fonts/RobotoCondensed-Bold.ttf",
italic = "../../../../../../fonts/RobotoCondensed-Italic.ttf",
bolditalic = "../../../../../../fonts/RobotoCondensed-BoldItalic.ttf"
)
showtext_auto(enable = TRUE) # enable showtext
##
theme_custom <- function() {
theme_bw(base_size = 10) +
theme_sub_axis(
title = element_text(
family = "Roboto Condensed",
size = 8
),
text = element_text(
family = "Roboto Condensed",
size = 6
)
) +
theme_sub_legend(
text = element_text(
family = "Roboto Condensed",
size = 6
),
title = element_text(
family = "Alegreya",
size = 8
)
) +
theme_sub_plot(
title = element_text(
family = "Alegreya",
size = 14, face = "bold"
),
title.position = "plot",
subtitle = element_text(
family = "Alegreya",
size = 10
),
caption = element_text(
family = "Alegreya",
size = 6
),
caption.position = "plot"
)
}
## Use available fonts in ggplot text geoms too!
ggplot2::update_geom_defaults(geom = "text", new = list(
family = "Roboto Condensed",
face = "plain",
size = 3.5,
color = "#2b2b2b"
))
ggplot2::update_geom_defaults(geom = "label", new = list(
family = "Roboto Condensed",
face = "plain",
size = 3.5,
color = "#2b2b2b"
))
ggplot2::update_geom_defaults(geom = "marquee", new = list(
family = "Roboto Condensed",
face = "plain",
size = 3.5,
color = "#2b2b2b"
))
ggplot2::update_geom_defaults(geom = "text_repel", new = list(
family = "Roboto Condensed",
face = "plain",
size = 3.5,
color = "#2b2b2b"
))
ggplot2::update_geom_defaults(geom = "label_repel", new = list(
family = "Roboto Condensed",
face = "plain",
size = 3.5,
color = "#2b2b2b"
))
## Set the theme
ggplot2::theme_set(new = theme_custom())
## tinytable options
options("tinytable_tt_digits" = 2)
options("tinytable_format_num_fmt" = "significant_cell")
options(tinytable_html_mathjax = TRUE)
## Set defaults for flextable
flextable::set_flextable_defaults(font.family = "Roboto Condensed")
2 References
- Daniel Kaplan and Randall Pruim. ggformula: Formula Interface for ggplot2 (full version). https://www.mosaic-web.org/ggformula/articles/pkgdown/ggformula-long.html
- Winston Chang (2024). R Graphics Cookbook. https://r-graphics.org
Error in utils::packageVersion(pkg_name): there is no package called 'ggstatplots'
Citation
BibTeX citation:
@online{v.2025,
author = {V., Arvind},
title = {Uncertainty},
date = {2025-10-01},
url = {https://madhatterguide.netlify.app/content/courses/Analytics/20-Inference/Modules/25-Uncertainty/},
langid = {en},
abstract = {In this module, we will explore the concept of uncertainty
in data analysis. We will discuss different types of uncertainty,
methods to quantify it, and how to communicate uncertainty
effectively in our findings.}
}
For attribution, please cite this work as:
V., Arvind. 2025. “Uncertainty.” October 1, 2025. https://madhatterguide.netlify.app/content/courses/Analytics/20-Inference/Modules/25-Uncertainty/.