set_font: set_font

View source: R/set_font.R

set_fontR Documentation

set_font

Description

setting font for ggplot (axis text, label, title, etc.)

Usage

set_font(p, family = NULL, fontface = NULL, size = NULL, color = NULL)

Arguments

p

ggplot object

family

font family; NULL (the default) keeps the family already used by the plot unchanged

fontface

font face, e.g. "bold", "italic" or the grid numeric codes 1 to 4

size

font size in points, the same unit used by element_text

color

font color

Details

The requested values are written into the plot theme, so text elements that inherit from theme(text=) keep their relative sizing (rel()). Text drawn by a layer (geom_text(), geom_label(), ggtree::geom_tiplab(), ...) does not follow the plot theme, so for those layers the values become layer parameters. An aesthetic that is already mapped with aes(), either in the layer or in the plot, is left alone: ggplot2 would otherwise let the constant parameter replace the mapped values and drop the corresponding legend along with it. Apply it to a finished plot, because a theme added afterwards can overwrite these settings.

Value

A modified ggplot object, which can still be extended with +.

Author(s)

Guangchuang Yu

Examples

library(ggplot2)
d <- data.frame(x=rnorm(10), y=rnorm(10), lab=LETTERS[1:10])
p <- ggplot(d, aes(x, y)) + geom_text(aes(label=lab), size=5)
set_font(p, family="Times", fontface="italic", color='firebrick')

ggfun documentation built on Oct. 9, 2026, 5:07 p.m.