Inspired by this awesome work: https://rud.is/b/2015/03/26/pre-cran-waffle-update-isotype-pictograms/
# initialize font db
install.packages("extrafontdb", repos = "http://cran.rstudio.com/")
## Installing package into 'C:/Users/yutani/Documents/R/win-library/3.2'
## (as 'lib' is unspecified)
## package 'extrafontdb' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Windows\Temp\RtmpKQ64NR\downloaded_packages
library(extrafont)
## Registering fonts with R
fa_font <- tempfile(fileext = ".ttf")
download.file("http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/fonts/fontawesome-webfont.ttf?v=4.3.0",
destfile = fa_font, method = "curl")
font_import(paths = dirname(fa_font), prompt = FALSE)
## Scanning ttf files in C:/windows/TEMP/RtmpKQ64NR ...
## Extracting .afm files from .ttf files...
## C:\Windows\Temp\RtmpKQ64NR\file158859507ad8.ttf => C:/Users/yutani/Documents/R/win-library/3.2/extrafontdb/metrics/file158859507ad8
## Found FontName for 1 fonts.
## Scanning afm files in C:/Users/yutani/Documents/R/win-library/3.2/extrafontdb/metrics
## Writing font table in C:/Users/yutani/Documents/R/win-library/3.2/extrafontdb/fontmap/fonttable.csv
## Writing Fontmap to C:/Users/yutani/Documents/R/win-library/3.2/extrafontdb/fontmap/Fontmap...
fonts()
## [1] "FontAwesome"
if (.Platform$OS.type == "windows") loadfonts("win")
## Registering font with R using windowsFonts(): FontAwesome
library(highlight)
library(dplyr)
##
## Attaching package: 'dplyr'
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(purrr)
##
## Attaching package: 'purrr'
##
## The following object is masked from 'package:dplyr':
##
## order_by
##
## The following objects are masked from 'package:utils':
##
## unzip, zip
library(stringr)
library(ggplot2)
fa_css <- tempfile(fileext = ".css")
download.file("http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.css", destfile = fa_css)
fa_parsed <- css.parser(fa_css)
## Warning in css.parser(fa_css): use of numbers in style names
fa_df <- fa_parsed[str_detect(names(fa_parsed), ":before")] %>%
unzip("content") %>%
.[[1]] %>%
data_frame(char_raw = .,
char = str_extract(char_raw, "[0-9a-f]+"),
char_int = strtoi(char, 16L),
codes = str_replace(names(.), ":before", ""))
fa_df
## Source: local data frame [519 x 4]
##
## char_raw char char_int codes
## 1 "\\f000" f000 61440 fa-glass
## 2 "\\f001" f001 61441 fa-music
## 3 "\\f002" f002 61442 fa-search
## 4 "\\f003" f003 61443 fa-envelope-o
## 5 "\\f004" f004 61444 fa-heart
## 6 "\\f005" f005 61445 fa-star
## 7 "\\f006" f006 61446 fa-star-o
## 8 "\\f007" f007 61447 fa-user
## 9 "\\f008" f008 61448 fa-film
## 10 "\\f009" f009 61449 fa-th-large
## .. ... ... ... ...
ggplot(mtcars) +
geom_text(aes(mpg, wt, colour = factor(cyl)),
label = intToUtf8(fa_df[fa_df$codes == "fa-car", "char_int"]),
family = "FontAwesome",
size = 12)