I've installed the 'extrafont' package in order to install an external font library Duality via the ttf_import() method. However, when specifying the font via the wordcloud method, I receive the following error:
Installation command:
# Assuming the font file, DUALITY_.ttf, is in the working directory (see link to font above)
font_import(".",FALSE,pattern="DUALITY")
Wordcloud command:
wordcloud(ap.d$word, ap.d$freq, scale=c(8,2), min.freq=10, vfont=c("Duality","plain"),
random.order=FALSE, rot.per=0, use.r.layout=FALSE, colors=pal2, fixed.asp=FALSE)
Output:
Error in strwidth(words[i], cex = size[i], ...) :
invalid 'vfont' value [typeface -2147483648]
In order to verify that the font is indeed installed, I issued the following commands
> choose_font("Duality")
[1] "Duality"
> fonts()
....[49] "Waree" "Duality"
How come the Duality font is not visible to the vfont parameter of wordcloud? And how do I make it visible to Cairo (the default renderer). TIA!
To complement previous answers, and explain how one can actually choose which fonts to use. First, import fonts (it is possible to set a path different from the default in
font_import()
To know which fonts are available:
This presents the exact reference for what to include as "font family". You can then issue the
wordcloud
command like this:Why
font = 1
? From?par()
, here's what it says about thefont
parameter:I've been able to overcome the same problem using the parameters passed to text
family
andfont
and described in?par
instead ofvfont
. Also I needed to load the font first. So the thing goes:Import the font (sorry, the link to Duality provided in OP is no longer available, I use Lucida Handwriting instead, available in windows):
Load (see this blog for details):
Wordcloud: