library(ggplot2)
p <- ggplot(mtcars) +
geom_point(
aes(
x = mpg,
y = hp
)
) +
labs(
x = "Miles per gallon",
y = "Horsepower",
title = "Horsepower relative to miles per gallon"
)
# the default fonts are Roboto (body) and Merriweather (titles)
# an error will occur if not loaded before using theme_hdx()
try(p + theme_hdx())
# you can change the base and title families
p + theme_hdx(base_family = "sans", title_family = "sans")
# supplying only base_family carries it over to title_family too
try(load_source_sans_3())
try(p + theme_hdx(base_family = "Source Sans 3"))
# or load Roboto and Merriweather using gghdx() or load_hdx_fonts()
try(load_hdx_fonts())
try(p + theme_hdx())
# we can change the axis line direction depending on the plot
p + theme_hdx(horizontal = FALSE)
# use the pre-2025 theme instead
p + theme_hdx(design = "legacy")
Run the code above in your browser using DataLab