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