r - knitr, cairo and ggplot2: font family 'Source Code Pro' not found in PostScript fontdatabase -
trying fix problem otf-fonts have (see how use otf-font in ggplot2 graphics?) found can use these fonts ggplot2.
using knitr rmd-files okay:
--- title: "fonttest" author: "me" date: "22. april 2015" output: html_document --- ```{r, echo=false} library(ggplot2) ggplot(mtcars, aes(x=wt, y=mpg, color=factor(gear))) + geom_point() + ggtitle("fuel efficiency of 32 cars") + xlab("weight (x1000 lb)") + ylab("miles per gallon") + theme(text=element_text(size=16, family="arial")) ```
but when want use latex (rnw-files) error:
\documentclass{article} \begin{document} \sweaveopts{concordance=true} <<>>= sys.setenv(lang = "en") library(ggplot2, quietly=true) @ <<>>= ggplot(mtcars, aes(x=wt, y=mpg, color=factor(gear))) + geom_point() + ggtitle("fuel efficiency of 32 cars") + xlab("weight (x1000 lb)") + ylab("miles per gallon") + theme(text=element_text(size=16, family="arial")) @ \end{document}
here's error:
writing file test.tex processing code chunks options ... 1 : echo keep.source term verbatim (test.rnw:6) 2 : echo keep.source term verbatim (test.rnw:13) error in grid.call.graphics(l_text, as.graphicsannot(x$label), x$x, x$y, : invalid font type calls: <anonymous> ... drawdetails -> drawdetails.text -> grid.call.graphics in addition: there 50 or more warnings (use warnings() see first 50) execution halted
i'm using mac os x mavericks.
update
i found work around using cairo:
\documentclass{article} \begin{document} <<>>= sys.setenv(lang = "en") library(ggplot2, quietly=true) library(cairo) @ <<dev='cairo_pdf'>>= ggplot(mtcars, aes(x=wt, y=mpg, color=factor(gear))) + geom_point() + ggtitle("fuel efficiency of 32 cars") + xlab("weight (x1000 lb)") + ylab("miles per gallon") + theme(text=element_text(size=16, family="source code pro")) @ \end{document}
but lot's of warnings:
## warning in grid.call(ltextbounds, as.graphicsannot(x$label), x$x,x$y, : font family 'source code pro' not found in postscript fontdatabase
i avoid suppressing these warnings. have rid of these warnings?
i found following solution:
i use
\usepackage{tikz}
and
<<plot, dev='tikz'>>
in .rnw file. doing way fonts of latex project in plots.
Comments
Post a Comment