r- emojifont package's font-awesome command not displaying icons in Windows 10

Viewed 1147

When i use the fontawesome command from the emojifont package I get a square not the icon i requested. I'm fairly new to R, there may be something very simple i'm missing but this has had me stuck for some time.

I'm running windows 10, R version is up to date, using RStudio. Reportedly these commands are working on a linux computer properly see previous discussion: Replace categorical values with traffic light colors

in another question the a user says to run Windows(). This made no difference, is it significant? using font awesome in ggplot

Example code

> library(emojifont)
> load.fontawesome()

> fontawesome('fa-circle')
[1] ""

> fontawesome('fa-apple')
[1] ""

> fontawesome('fa-at')
[1] ""

Update: I can reproduce some simple examples online but not others.

set.seed(123)
x <- rnorm(10)
set.seed(321)
y <- rnorm(10)
plot(x, y, cex=0)
text(x, y, labels=emoji('cow'), cex=1.5, col='steelblue', family='EmojiOne')

d <- data.frame(x=x, y=y,
                label = sample(c(emoji('cow'), emoji('camel')), 10, replace=TRUE),
                type = sample(LETTERS[1:3], 10, replace=TRUE))

library("ggplot2")
ggplot(d, aes(x, y, color=type, label=label)) +
  geom_text(family="EmojiOne", size=6)

This works properly as you can see below Correct Output

However this code only produces squares (and most other examples i have tried)

set.seed(2016-03-09)
fa <- fontawesome(c('fa-github', 'fa-weibo', 'fa-twitter', 'fa-android', 'fa-coffee'))
d <- data.frame(x=rnorm(20),
                y=rnorm(20),
                label=sample(fa, 20, replace=T))

ggplot(d, aes(x, y, color=label, label=label)) +
  geom_text(family='fontawesome-webfont', size=6)+
  xlab(NULL)+ylab(NULL) +
  theme(legend.text=element_text(family='fontawesome-webfont'))

enter image description here

In the Image above (and most examples i have tried) I get the squares instead of Icons. Any thoughts as to why?

1 Answers

I don't think it's supposed to print on the console, but only in plots.

Basically, what you are doing is asking emojifont/fontawesome, which of the possible over 1 million codepoints in Unicode correspond to a "circle" (it's code point f51d), and then print that character.

In plotting, you can say that you want that character to be printed in a certain font, and if you choose "fontawesome-webfont", such as as in the examples from emojifont, those circles will be plotted.

ggplot(d, aes(x, y, color=label, label=label)) +
    geom_text(family='fontawesome-webfont', size=6)

Now if you would have chosen a different font-family, those labels would be printed in a different font.

Except that in practice, someone making a font will be carefully thinking about how to draw their a's, and b's, etc. But they won't have much time to think about how to draw "codepoint f51d", even if they knew that was only supposed to be a circle. And they don't expect anyone to ever use such an obscure codepoint.

So they take care of characters they expect to be used, and just use a placeholder for other characters, such as ""

And in the console, you will have a default font, depending on what console you are using, e.g. in my Rstudio-installation "Lucida console" is used. Not sure what font is shown in your console, but apparently it doesn't have a nice representation fro "codepoint f51d"

So in order to show it, you need to show it in the right font: fontawesome. Which means either plotting, or setting your console to use fontawesome. Although I'm not sure if that last one will work effectively, it might cause simple characters such as "A" to be showing placeholders as well, or maybe they've used it for showing something entirely different.

And the thing about using windows() is because the standard-rstudio-plotwindow sometimes uses its own defaults, and might not find fontawesome. But that has only to do with plotting in RStudio.

Related