9

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"

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
Lauren
  • 110
  • 1
  • 10

4 Answers4

4

I know this question was asked and answered quite a while ago, but the answer didn't help me with my code, and I found something that did from this source: https://www.listendata.com/2019/06/create-infographics-with-r.html They have a step-by-step directions for downloading fontawesome using the extrafont library. Really easy. Hope this helps someone! Basically, download the fontawesome-webfont.ttf, then:

library(extrafont)
extrafont::font_import (path="C:/Users/insert/your/own/path", pattern = "awesome", prompt = FALSE)
loadfonts(device = "win")
# check to see if it works:
fonts()[grep("Awesome", fonts())]
#returns fontawesome

Then use use_glyph = argument in making your waffle chart.

  • here, what really helped me is the use of `showtext::font_add` as suggested in that link. Thanks for pointing to the link – tjebo Jan 05 '23 at 15:45
3

For anyone who ends up here in 2021 and fails to get it working with extrafont, here is an alternative approach:

  1. Use the legacy FontAwesome ttf, that Silviculturalist linked to: https://github.com/FortAwesome/Font-Awesome/releases/tag/v4.7.0
  2. Extract fontawesome-webfont.ttf to your work directory (or some directory you can access)
  3. Use the waffle, emojifont and showtext packages to create the chart, sample code below
install.packages(c("waffle", "emojifont", "showtext"))
 
library(waffle)
library(emojifont)
library(showtext)

font_add(family = "FontAwesome", 
         regular = "fontawesome-webfont.ttf")

waffle(c(5,12,18), rows = 5, use_glyph = "subway", glyph_size = 10, 
title = "Subways!", legend_pos="right")
bencekd
  • 1,575
  • 1
  • 12
  • 8
  • 1
    thanks for the answer, I tried to reproduce your detailed answer (1. Download v.4.7, 2 place it on the project's root, 3 load packages, 4, add font via showtext, 5 run your waffle code), but I get the same error as everyone else: "Error: Font [Font Awesome 5 Free Solid] not found. Please install it and use extrafont to make it available to R". You can check my sessioninfo() and code here: https://gist.github.com/ccamara/f85f3e5a8fb2be0d1a3d375a65ac5bb4 Do you happen to have any clue? – ccamara Aug 24 '21 at 13:49
2

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.

ekstroem
  • 5,957
  • 3
  • 22
  • 48
  • I just tried emojifont and used the exact code here. I once again received the error code "Error: FontAwesome not found. Install via: https://github.com/FortAwesome/Font-Awesome/tree/master/fonts" – Lauren Jul 16 '18 at 16:14
  • @Lauren I think the problem might be the otf-version of the font and not the ttf. I've updated my answer with another suggestion – ekstroem Jul 16 '18 at 22:36
  • the otf was the issue. You have to use the ttf found on github (though it isn't located at the address the error provides) Now it is loaded, but I get dots, which is a step above the squares and error message I guess – Lauren Jul 25 '18 at 21:02
  • This worked for me: https://stackoverflow.com/a/74589250/4438465 – Juan C Nov 27 '22 at 10:36
2

You may want to try using FontAwesome v. 4.7 I had the same issue as you but it resolved itself immediately when I installed the .ttf version.