R ggplot2 fonts issue - r

I'm trying to get the xkcd fonts working in R with ggplot2. However I'm running into some issues.
Here is what I have done so far.
1) Installed the "Humor Sans" font from the xkcd site in the directory ~/.fonts
2) Installed the "extrafont" package. This installation worked smoothly.
3) Load the library
library(extrafont)
However when I try to import the font I get the following error.
> font_import(pattern="Humor Sans")
Importing fonts may take a few minutes, depending on the number of fonts and the speed of the system.
Continue? [y/n] y
Scanning ttf files in /usr/share/fonts/, ~/.fonts/ ...
Extracting .afm files from .ttf files...
Error in data.frame(fontfile = ttfiles, FontName = "", stringsAsFactors = FALSE) :
arguments imply differing number of rows: 0, 1
Any suggestions on what I could be doing wrong or what else I should be doing?
Thanks much in advance
edit: Running ubuntu 12.04

Have you tried:
font_import(paths = "~/.fonts", pattern="Humor Sans")
It does not appear to me that "~/.fonts" is the default font folder for a Mac, so if that is (or is not) your OS, you should include more details when you edit your original question.

Related

extrafont package not importing fonts (need to use in ggplot)

I am dealing with fonts in R for the first time. I have tried every solution I could find on stack and elsewhere to get fonts into R for me, but thus far I have had no success. At the most basic level, this is what I am trying to do:
install.packages('extrafonts')
library(extrafonts)
font_import()
At that point, I run into a big mess that I'm not really understanding well. My console shows me that first R is scanning ttf files, then extracting .afm files from .ttf files, and then it repeatedly references these long file extensions followed by ": No FontName. Skipping."
A full piece of the error message looks like this:
/System/Library/Fonts/Supplemental/Arial Unicode.ttfsh: line 1: 39188 Segmentation fault: 11 '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/System/Library/Fonts/Supplemental/Arial Unicode.ttf' '/var/folders/3h/yfpgl52j7rbb5l68lrwdvv_m0000gn/T//RtmpgwAvQc/fonts/Arial Unicode' 2>&1
: No FontName. Skipping.
Does anyone have any idea exactly what is going on here?
I know that the fonts aren't importing because when I run loadfonts() followed by fonts() or fontstable(), I get NULL. And when I try to pull a font other than the three native families in R into the theme of my ggplot function, the plot doesn't generate.

Problem to import fonts with font_import : 'CreateProcess failed to run'

I am trying to import fonts for ggplot2 graphs as in described here at work and it does not function (I succeeded easily at home).
Whether I try to do all fonts at the same time,
font_import()
y
Or font by font (amusingly, they are displayed by default by windows in a different case than how they are actually stored) :
font_import(pattern = "arial.ttf")
y
I get the following error message :
Scanning ttf files in C:\windows\Fonts ...
Extracting .afm files from .ttf files...
C:\Windows\Fonts\ahronbd.ttfError in system2(ttf2pt1, c(args, shQuote(ttfiles[i]), shQuote(tmpfiles[i])), :
'CreateProcess' failed to run 'C:\Users\name\DOCUME~1\R\WIN-LI~1\3.6\Rttf2pt1\exec\ttf2pt1.exe -a -G fAe "C:\Windows\Fonts\ahronbd.ttf" "C:\Users\name\AppData\Local\Temp\RtmpCyAu4H/fonts/ahronbd"'
And I have not found anything particularly helpful on the matter.
One reason might be speceific restrictions set by the IT at me company, but I am unsure where to start.
Is there a relatively simple way to see at what point the process is stopping ?
If not, would it be doable to copy/paste fonts "by hand", but then where am I supposed to paste what ?
I have checked that I have indeed the Arial font :

Why do I get an intermittent error in grid.Call with ggplot? [duplicate]

I just installed RStudio on Mac OS X, version 10.7.3.
After executing the following commands
library(ggplot2)
qplot(mpg, wt, data=mtcars)
I get the following error:
Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
Polygon edge not found
In addition: Warning messages:
1: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
no font could be found for family "Arial"
2: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
no font could be found for family "Arial"
How do I fix this?
this happened to me and i discovered that the arial font file had been disabled. first check to see if Arial.ttf has been moved to the disabled fonts directory. from the terminal:
ls /Library/Fonts\ Disabled
if so, move it back to the active fonts directory.
sudo mv /Library/Fonts\ Disabled/Arial.ttf /Library/Fonts
log out, log in, then open the 'Font Book' application. in my case, arial was present before hand, but it was the Microsoft version stored in /Library/fonts/Microsoft/. Font Book may now show a yellow triangle next to the font name, indicating that multiple copies of the font exist. highlight the font name and chose the Resolve Duplicates command from the Edit menu. this should disable the Microsoft copy, which you can confirm by selecting one of the arial type faces (click the expand triangle next to the font name), right-click on the one labelled Off, and choose Reveal in Finder, which should open a window to Microsoft fonts directory.
So I bumped into the same problem with a code that was working just a few weeks before, and no massive update of anything on the computer (except maybe the OS, now that I get to think about it...).
The way I solved it is that I forced the graphic window to open first by calling
quartz()
before my graphs, and it did the trick. Still unsure about the font, I seem to have the Arial in place.
After a few trials, I think this "fix" could help.
First try running this to ensure the fonts actually exist:
loadfonts(dev="win")
If they do, call the following to ensure the name you're calling is similar to that R knows:
windowsFonts()
Otherwise, try the following:
library(extrafont)
extrafont::font_import()
The above fixed problems for me. Hope someone in the future may be helped by the same.
After coming across the same problem again and again and trying different solutions I have decided to source the Arial font externally and add it to the Font Book. Prior to this exercise I had a number of fonts that came with MS Office, like Arial Black, Arial Narrow and so no but no plain Arial font visible. I'm guessing that this can be explained by the odd font policy that MS applications on Mac are applying, which is discussed in a greater detail here. Nevertheless, it appears that adding font externally solved the problem.
I added an extra parameter to my qqplot() function like this:
theme(text=element_text(family="Garamond", size=14))
and sure enough - got a chart. End result then is:
ggplot(train, aes(x = pclass, fill = factor(survived))) +
geom_bar() +
xlab("Pclass") +
ylab("Total Count") +
labs(fill = "Survived") +
theme(text=element_text(family="Garamond", size=14))
I did open Font Book and on my system (Mac OSX 10.12.3) is shows Arial as being off. I do have Microsoft apps installed including MS Excel but I cannot at this point correlate the disabling of any font with the install of any MS app.
HTH
As others have cited, this issue definitely seems to be related to a Microsoft Office upgrade (my company had just upgraded the software immediately before the issue surfaced).
After attempting to run a simple ggplot2 plot, I received the following Error and Warning:
Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
polygon edge not found
Warning messages:
1: In grid.Call(C_stringMetric, as.graphicsAnnot(x$label)) :
no font could be found for family "Arial"
I resolved this issue by performing the following actions:
(1) Open Font Book
(2) Navigate to the Arial Font
(3) Right Click -> "Restore Font"
Then the plot rendered perfectly.
I hope this helps!
For mac operating system, i tried many options but in the end following worked.
- open font book and remove disable (enable) arial fonts.
- restart the computer.
I've faceted the same issue and it was enough reseting the plot area (dev.off()).
I resolved by going to Font Book, going to File -> Restore Standard Fonts.
I ran into the same problem (interestingly, I received the error when calling the "spplot" function rather than any of the ggplot2 functions). Because I had recently installed MS Office for Mac, I tried disabling the MS duplicate Arial font as was previously suggested, but still received the error message repeatedly even after doing this. I ended up simply removing all MS Office duplicate fonts (Go-->Computer-->Macintosh HD--->Library-->Fonts and then move the Microsoft folder to the trash). I'm not sure what effect this will have on my MS applications, but it seems to have remedied my R issues, which is more important to me at this point anyway!
Working on MacOS, I got the same error message with the warnings mentioning instead of Arial the Roboto Condensed fonts. So I installed those, which removed the warnings, but not the error message.
Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
polygon edge not found
Then I found at https://community.rstudio.com/t/still-fighting-with-grid-call-c-textbounds-as-graphicsannot-x-label-x-x-x-y-polygon-edge-not-found-error/65559 the tip to re-install X11 https://www.xquartz.org .
After that the error disappeared ... but it still did not plot when the code was in an R file. It does work, though, when I knit in RStudio from an R-markdown document.
I just ran into the same problem after updating my OS and a fresh install of MS Office, which seems to be the culprit.
Since I couldn't get the terminal approach to work, I simply went straight to the Font Book and enabled the disabled fonts (Arial, Times New Roman, Verdana) manually. After restarting, everything seems to be working fine now.
This strikes me as the most naïve solution but it's also easiest to implement imho.
I encountered a similar problem using the function:
ggarrange (ggpubr package)
It was solved by manually deactivating and activating the package (by clicking on the package in "packages"). Maybe this also helps others :)
Bizarre error. But for me, on mac, the solution was simple: simply update Xquartz.
Open spotlight search with cmd + space, search for Xquartz
Once, opened, go to about -> Check for updates -> Update.
I understand that both R console jobs and Rstudio started failing out in their graphics plotting duties, and that now when you run trivial plot request, you receive failure error, and no plot.
Have you reset the sessions ? (Ctrl+Shft+F10)
Sometimes sessions can get corrupted after all.
Alternatively, if you would like something else to try, before that route, it might be worth halting the graphics device. dev.off() and trying that elementary plot again.
Of course, if your issue is persistent, across to new sessions, then this answer does not apply.
First, as a quick test as to whether this error is the result of a font-related issue, you can try plotting without any text (see code below).
# test whether error is being generated by a font issue
library(ggplot2)
# try removing all fonts to test if issue is font-related
# by using theme(text = element_blank())
mtcars %>%
ggplot() +
aes(x = wt, y = mpg) +
geom_point() +
theme(text = element_blank())
Second, if the text-free version of your plot works and you're on a Mac, try reinstalling ggplot2. Recently, after trying all the other approaches, I found running install.packages("ggplot2") and restarting RStudio was the only thing that solved the problem.
Third, more than a year ago fixing Arial (as suggested above) was helpful:
Hit Command-Space and type Font Book to open that app
Right-click on Arial and select Disabled Arial
Right-click on Arial and select Enable Arial
When prompted to Resolve Duplicates select Resolve Automatically
Quit out of RStudio and re-open RStudio (I didn't need to reboot my computer)
Re-run plotting code as test (in my case it worked fine without the error)

rgl does not find font family

I face a strange issue with R and package rgl on my Desktop Ubuntu 14.04. While on my laptop with Ubuntu 12.04
title3d(xlab="Mean Market 1", pos=c(1,0,0), col="black",adj=c(0.8,0.8),
family="Times", cex=1.1)
works perfectly, I get a warning message
font family "Times" not found, using "bitmap"
on my desktop pc. Plotting works, but titles are pretty small. If I check
names(X11Fonts())
# [1] "serif" "sans" "mono" "Times" "Helvetica"
# [6] "CyrTimes" "CyrHelvetica" "Arial" "Mincho"`
but none works. I installed freetype2 package, reinstalled rgl package but the warning is still there. I tried sans font etc., as well.
Carsten Oppitz,
I experienced the same issues that you mention above in my computer with Ubuntu 14.04. After searching for fixing them for a long time and nothing worked, the instructions below, copied from http://www.smnd.sk/kotanyi/index.php?page=rgl, did work perfectly:
a) Terminal, check that you have GNU version >= 3.80:
make -v
b) Download FreeType from: https://sourceforge.net/projects/freetype/files/ e.g. latest version.
c) Extract the downloaded file, enter in the directory where it is saved and type in:
./configure
make
sudo make install
d) Still need to rebuild rgl in R: download its source code from the link appearing in the first link above; without extracting the file, type in:
R CMD INSTALL name_of_archive.tar.gz
e) Enjoy any text size (that R supports) in plot3d objects.
You can only really count on "serif", "sans", "mono" and "symbol", unless you've used rglFonts to install additional Freetype font files. So "Times" should be "serif".

xkcd style graph - error with registered fonts

I want to create the graph, like at the link for the previous topic, but receive error:
In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : Font
family not found in Windows font database
Though fonts() shows "Humor Sans" and "xksd" are installed. I use Windows 7 64bit, R 2.15.2 RStudio 0.96.331.
Any suggestions how to fix it?
I think I had the same problem some time ago. Here is what I did:
Put Humor-Sans font file into your project folder and make sure your working directory is set to the same.
Import the fonts (this might take a while) by calling
font_import()
Look through the list of fonts and see if you can find Humor-Sans by
fonts()
Load the fonts
loadfonts(device = "win")
Let me know if it works!

Resources