| set_font | R Documentation |
setting font for ggplot (axis text, label, title, etc.)
set_font(p, family = NULL, fontface = NULL, size = NULL, color = NULL)
p |
ggplot object |
family |
font family; |
fontface |
font face, e.g. |
size |
font size in points, the same unit used by
|
color |
font color |
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.
A modified ggplot object, which can still be extended with +.
Guangchuang Yu
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')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.