2016-07-28 6 views
0

私は.Rnwビーマープレゼンテーションの中でカスタムフォントを使いたいと思っていました。スウェーブとビーマーを使ったカスタムggplotフォント

\documentclass{beamer} 
\begin{document} 
\begin{frame}[plain] 
<<echo=FALSE>>= 
library(ggplot2) 
library(extrafont) 
@ 
\begin{figure} 
\centering 
<<label = test, fig=TRUE, include=FALSE, echo=FALSE, message=FALSE>>= 
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() + 
    ggtitle("Fuel Efficiency of 32 Cars") + 
    xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") + 
    theme_bw() + 
    theme(text=element_text(family="Garamond", size=14)) 
@ 
\includegraphics[width=\textwidth]{test} 
\end{figure} 
\end{frame} 
\end{document} 

と、エラーメッセージは、次のようになります:エラーを再現し、最小限の作業例がある

Writing to file test.tex 
Processing code chunks with options ... 
1 : keep.source term verbatim (test.Rnw:6) 
Registering fonts with R 
2 : keep.source term verbatim pdf (label = test, test.Rnw:12) 
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 

しかし、私は、コンソールでggplotコマンドを使用する場合、すべてが正常に見えます。

ご協力いただければ幸いです。

+0

が、私は.Rnwファイルを使用して、あなたのエラーを再現することができる唯一の方法私がインストールされていないフォントを使用しようとした場合です。コンソールでは、Rがデフォルトのフォントに戻り、アンインストールされたフォントを使用しようとすると警告が表示されます。 –

+0

それは変です。私が 'fonts()'を見ると、フォントがインストールされていることがはっきりとわかり、 'extrafont'にアクセスできると思います。 – Pascal

答えて

0

申し訳ありませんが、実際問題はフォントがインストールされていないことです。しかし、私はGaramondを例として使用していて、実際にotfフォントFira Sansを使用したいので、showtextパッケージを使用しました。

ここで動作するコードです:

\documentclass{beamer} 
\begin{document} 
\begin{frame}[plain] 
<<test, fig=TRUE, echo=FALSE, width=6, height=4>>= 
library(ggplot2) 
library(showtext) 
font.add.google("Fira Sans", "fira") 
showtext.auto() 
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + 
    ggtitle("Fuel Efficiency of 32 Cars") + 
    xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") + 
    theme_bw() + 
    theme(text = element_text(family = "fira")) 
@ 
\end{frame} 
\end{document} 
関連する問題