Skip to content

Instantly share code, notes, and snippets.

@grigory93
Last active April 24, 2016 20:49
Show Gist options
  • Save grigory93/50f613f3fc8aea94a7eba4953f8a3ad7 to your computer and use it in GitHub Desktop.
Save grigory93/50f613f3fc8aea94a7eba4953f8a3ad7 to your computer and use it in GitHub Desktop.
library(ggplot2)
library(ggthemes)
fontTable = fonttable()
fontTable$Face = with(fontTable, ifelse(Bold & Italic, "bold.italic",
ifelse(Bold, "bold",
ifelse(Italic, "italic", "plain"))))
fontTable$Face = factor(fontTable$Face, levels = c("plain","bold","italic","bold.italic"), ordered = TRUE)
fontTable$FamilyName = factor(fontTable$FamilyName, levels = rev(sort(unique(fontTable$FamilyName))), ordered = TRUE)
p = ggplot(fontTable) +
geom_text(aes(x=Face, y=FamilyName, label=FullName, family=FamilyName, fontface=Face)) +
labs(title="Windows Fonts in R", x=NULL, y=NULL) +
theme_tufte() +
theme(axis.ticks = element_blank(),
axis.text=element_text(size=12, colour="gray40", family='Arial'),
axis.text.x=element_text(face=c("plain","bold","italic","bold.italic")),
plot.title=element_text(size=16, family='Arial'))
ggsave("images/font_ggplot_map.png", width = 10, height = 33)
install.packages('extrafont')
library(extrafont)
font_import()
# This tries to autodetect the directory containing the TrueType fonts.
# If it fails on your system, please let me know.
# Vector of font family names
fonts()
# Show entire table
fonttable()
# Register fonts for Windows bitmap output
loadfonts(device="win")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment