invalid font type on export to PDF

6,647 views
Skip to first unread message

Crump, Ron

unread,
Oct 8, 2015, 5:09:18 AM10/8/15
to ggp...@googlegroups.com
Hi everyone,

A student here has to create some graphs with fonts of a specific size and
family (Arial) for inclusion in a poster. She has the graph apparently
working nicely, but on writing to the PDF device gets and error:

Error in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y,
:
invalid font type


I can reproduce this with a minimal example on my Mac (the student is also
on a Mac):

DF<-structure(list(x = 1:10, y = c(3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7,
7.5, 8)), .Names = c("x", "y"), row.names = c(NA, -10L), class =
"data.frame")
p1<-ggplot(DF,aes(x=x,y=y))+geom_line()+xlab("my x axis")+ylab("my y axis²)
pdf(file="play.pdf",height=4,width=5)
p1+theme(axis.title=element_text(face="plain",size=12,family="Arial²))
dev.off()

I am on R 3.2.2, ggplot2 1.0.1, MacOSX 10.10.5.

If I just print the p1+theme(axis.titleŠ) bit to the default graphics
device, I get no error (but I wonder whether I am seeing Arial or a
substituted generic sans-serif, not sure).

Did a web search, and found this
http://stackoverflow.com/questions/31327012/exporting-ggplot2-grid-to-pdf-e
rror-error-in-grid-call-graphics-invalid-fon

But the solution for them was to remove multiple re-definitions of text
bits in calls to theme calls, which I do not think I have in this simple
example.

Any suggestions?

Thanks.

Ron.

ANTONIOSPARS GITONGA

unread,
Oct 8, 2015, 5:51:43 AM10/8/15
to Crump, Ron, ggp...@googlegroups.com
Hallo
this should work just fine.

DF<-structure(list(x = 1:10, y = c(3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7,
7.5, 8)), .Names = c("x", "y"), row.names = c(NA, -10L), class =
"data.frame")
p1<-ggplot(DF,aes(x=x,y=y))+geom_line()+xlab("my x axis")+ylab("my y axis² ")
pdf(file="play.pdf",height=4,width=5)
p1+theme(axis.title=element_text(face="plain",size=12,family="Arial²))
dev.off()

antonio


--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Crump, Ron

unread,
Oct 8, 2015, 6:26:42 AM10/8/15
to ANTONIOSPARS GITONGA, Crump, Ron, ggp...@googlegroups.com

>Hallo
>this should work just fine.

I thought it was ok, but there is something wrong.

So I tried installing the extrafont package

library(extra font)
font_import()

And then
dput(kk[grepl("arial",kk$FamilyName,ignore.case=TRUE),])
Gives:
structure(list(package = c(NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA), afmfile = c("Arial Black.afm.gz", "Arial Bold Italic.afm.gz",
"Arial Bold.afm.gz", "Arial Italic.afm.gz", "Arial.afm.gz", "Arial
Narrow.afm.gz",
"Arial Narrow Bold.afm.gz", "Arial Narrow Bold Italic.afm.gz",
"Arial Narrow Italic.afm.gz", "Arial Rounded Bold.afm.gz", "Arial
Unicode.afm.gz"
), fontfile = c("/Library/Fonts/Arial Black.ttf",
"/Library/Fonts/Microsoft/Arial Bold Italic.ttf",
"/Library/Fonts/Microsoft/Arial Bold.ttf", "/Library/Fonts/Microsoft/Arial
Italic.ttf",
"/Library/Fonts/Microsoft/Arial.ttf", "/Library/Fonts/Arial Narrow.ttf",
"/Library/Fonts/Arial Narrow Bold.ttf", "/Library/Fonts/Arial Narrow Bold
Italic.ttf",
"/Library/Fonts/Arial Narrow Italic.ttf", "/Library/Fonts/Arial Rounded
Bold.ttf",
"/Library/Fonts/Arial Unicode.ttf"), FullName = c("Arial Black",
"Arial Bold Italic", "Arial Bold", "Arial Italic", "Arial", "Arial
Narrow",
"Arial Narrow Bold", "Arial Narrow Bold Italic", "Arial Narrow Italic",
"Arial Rounded MT Bold", "Arial Unicode MS"), FamilyName = c("Arial
Black",
"Arial", "Arial", "Arial", "Arial", "Arial Narrow", "Arial Narrow",
"Arial Narrow", "Arial Narrow", "Arial Rounded MT Bold", "Arial Unicode MS"
), FontName = c("Arial-Black", "Arial-BoldItalicMT", "Arial-BoldMT",
"Arial-ItalicMT", "ArialMT", "ArialNarrow", "ArialNarrow-Bold",
"ArialNarrow-BoldItalic", "ArialNarrow-Italic", "ArialRoundedMTBold",
"ArialUnicodeMS"), Bold = c(FALSE, TRUE, TRUE, FALSE, FALSE,
FALSE, TRUE, TRUE, FALSE, FALSE, FALSE), Italic = c(FALSE, TRUE,
FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE),
Symbol = c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE), afmsymfile = c(NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA)), .Names = c("package", "afmfile",
"fontfile", "FullName", "FamilyName", "FontName", "Bold", "Italic",
"Symbol", "afmsymfile"), row.names = 9:19, class = "data.frame")


So there appears to be Arial font information available. But when writing
to the PDF device it still fails with the same ³invalid file type² error.

Ron.

ANTONIOSPARS GITONGA

unread,
Oct 8, 2015, 6:43:38 AM10/8/15
to Crump, Ron, ggp...@googlegroups.com
run what i sent you last i have added a "

antonio

Crump, Ron

unread,
Oct 8, 2015, 6:59:46 AM10/8/15
to ANTONIOSPARS GITONGA, Crump, Ron, ggp...@googlegroups.com

>run what i sent you last i have added a "

Sorry for any confusion, the example I sent got corrupted by Outlook. It
should have read:

DF<-structure(list(x = 1:10, y = c(3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7,
7.5, 8)), .Names = c("x", "y"), row.names = c(NA, -10L), class =
"data.frame")
p1<-ggplot(DF,aes(x=x,y=y))+geom_line()+xlab("my x axis")+ylab("my y axis")
pdf(file="play.pdf",height=4,width=5)
p1+theme(axis.title=element_text(face="plain",size=12,family="Arial"))
dev.off()


And the problem remains.

What you sent just added the " after axis, yes? I tried to run that but
had to then correct the 2 after Arial and then the problem was still there.

Ron.

ANTONIOSPARS GITONGA

unread,
Oct 8, 2015, 7:17:33 AM10/8/15
to Crump, Ron, ggp...@googlegroups.com
the problem is on the font database install package extrafont

Warning messages:
1: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
2: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
3: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
4: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
5: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
6: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
7: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
8: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
9: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database
10: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  font family not found in Windows font database

antonio

Crump, Ron

unread,
Oct 8, 2015, 7:44:19 AM10/8/15
to ANTONIOSPARS GITONGA, Crump, Ron, ggp...@googlegroups.com
Antonio,


>the problem is on the font database install package extrafont
>
>Warning messages:
>1: In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
> font family not found in Windows font database

You are quite right, Antonio. I saw the error message and didn¹t look at
the warnings (idiot that I am). A quick rummage around, and it appears
that I needed to do a loadfonts() after the font importing.

That has it sorted now.

Cheers,
Ron.

Reply all
Reply to author
Forward
0 new messages