Search code examples
rfont-awesomewaffle-chart

Font Awesome in R, loaded but not found by waffle


I downloaded the otf files from this website. My IT dept installed "Font Awesome 5 Free Regular" and I used

library(extrafont)
font_import()
loadfonts(device = "win")

I can see Font Awesome as "Font Awesome 5 Free Regular" is registered. When I tried to use it with this test code:

waffle(c(50, 30, 15, 5), rows = 5, use_glyph = "music", glyph_size = 6)

I get

Error: FontAwesome not found. Install via: https://github.com/FortAwesome/Font-Awesome/tree/master/fonts

but that link doesn't go anywhere.

I would like to use Font Awesome (or a good alternative) to make interesting waffle charts. Did I load the font incorrectly? Is there a better alternative I am missing? I have been using this article as a guide. I have also read a related question here on stackoverflow, but it did not help. I have restarted Rstudio (and the computer) several times and no luck.

Update

Still not working. I have removed and reinstalled the waffle and emojifont packages. I Still get the error code : "Error: FontAwesome not found. Install via: https://github.com/FortAwesome/Font-Awesome/tree/master/fonts"


Solution

  • If you are going to use the font-awesome glyphs in ggplot2 plots then you can use the wonderful emojifont package. No need to add the font manually yourself.

    library("emojifont")
    library("waffle")
    waffle(c(50, 30, 15, 5), rows = 5, use_glyph = "music", glyph_size = 4)
    

    That produces the graph you are after:

    enter image description here

    Update: Since you have installed the otf fonts and not the ttf fonts that might be the cause of your problems. The load.fontawesome() function in the emojifontpackage has a default argument:

    load.fontawesome(font = "fontawesome-webfont.ttf")
    

    You could try to 1) either install the ttf version of the fonts or 2) call

    load.fontawesome(font = "fontawesome-webfont.otf")
    

    before plotting (although I'm not sure the latter will work). Worth a try though.