3
尝试修复我遇到的otf-fonts问题(请参阅How to use otf-font in ggplot2 graphics?)我发现可以将这些字体与ggplot2一起使用。knitr,cairo和ggplot2:在PostScript中找不到的源代码Pro'fontdatabase
使用knitr与RMD-文件是好的:
---
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"))
```
但是,当我想用胶乳(RNW文件)我得到一个错误:
\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}
这里的错误:
Writing to file test.tex
Processing code chunks with 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 were 50 or more warnings (use warnings() to see the first 50)
Execution halted
我正在使用Mac OS X Mavericks。
更新
我发现了一个变通使用开罗:
\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}
但现在我得到的警告的很多的:
## Warning in grid.Call(LtextBounds, as.graphicsAnnot(x$label), x$x,x$y, : font family 'Source Code Pro' not found in PostScript fontdatabase
我想,以避免抑制这些警告。那么我需要做些什么来摆脱这些警告呢?
我想知道为什么你有'\ SweaveOpts',所以我发现有些相关的问题,检查出来(Yihui的答案):http://stackoverflow.com/questions/15040064/knitr-compile-problems-with-rstudio -windows – tonytonov
也许0应该是O? –
@tonytonov首先我想知道为什么我总是把这条线弄回来。但在我的试验和错误期间,我转向Sweave。但重新设置为knitr我仍然得到错误:退出行15-22(test.Rnw) grid.Call.graphics中的错误(L_text,as.graphicsAnnot(x $ label),x $ x,x $ y, : 无效字体类型 电话:针织... drawDetails - > drawDetails.text - > grid.Call.graphics 另外:有50个或更多的警告(使用警告()看到的第一个50) 停止执行 – JerryWho