使用knitr时ggplot2图形文本字体大小的格式设置

使用knitr时ggplot2图形文本字体大小的格式设置,r,knitr,rstudio,tikz,R,Knitr,Rstudio,Tikz,我的印象是,如果我使用tikz设备(我今天第一次尝试),图形文本将与Latex文档的其余部分(使用Knitr/RStudio生成)中的文本保持一致。然而,我看到(或试图看到)(有或没有tikz)的是我的图形中非常小的字体。要演示的示例代码: \documentclass[12pt,a4paper]{article} \begin{document} Here is some text <<eg, dev='tikz', size='normalsize',fig.width=1

我的印象是,如果我使用tikz设备(我今天第一次尝试),图形文本将与Latex文档的其余部分(使用Knitr/RStudio生成)中的文本保持一致。然而,我看到(或试图看到)(有或没有tikz)的是我的图形中非常小的字体。要演示的示例代码:

\documentclass[12pt,a4paper]{article}

\begin{document}

Here is some text

<<eg, dev='tikz', size='normalsize',fig.width=12, fig.height=5, fig.cap="ggplot theme not adjusted", echo=FALSE, message=FALSE, warning=FALSE>>=
require(ggplot2)
ggplot(cars) + geom_histogram(aes(speed), binwidth=1)
@


<<egWithTheme, dev='tikz', size='normalsize',fig.width=12, fig.height=5, fig.cap="ggplot element text size 30", echo=FALSE>>=
ggplot(cars) + geom_histogram(aes(speed), binwidth=1) + theme(text=element_text(size=30))
@

<<increasing dpi, dev='tikz', size='normalsize',fig.width=12, fig.height=5, dpi=300, fig.cap="dpi set to 300", echo=FALSE>>=
ggplot(cars) + geom_histogram(aes(speed), binwidth=1)
@

\end{document} 
\documentclass[12pt,a4paper]{article}
\开始{document}
这里有一些文字
=
需要(ggplot2)
ggplot(汽车)+几何图形直方图(aes(速度),BINWITH=1)
@
=
ggplot(汽车)+几何柱状图(aes(速度),binwidth=1)+主题(文本=元素文本(大小=30))
@
=
ggplot(汽车)+几何图形直方图(aes(速度),BINWITH=1)
@
\结束{document}
三个结果图的屏幕截图:

为实现图形和文档中字体大小的一致性,建议采用什么方法


谢谢。

内置的
theme()
theme\u bw()
这样的层可以将点大小作为参数,并放大/缩小标签。试着在你的情节中加入
+theme\u bw(8)
。@Andrew,不,那没用。无论如何,感谢使用相同的fig.width/fig.height和out.width/out.height值,例如,
fig.width=4,fig.height=3,out.width=“4in”,out.height=“3in”
@kohske是正确的,您的绘图尺寸比LaTeX使用的纸张大得多;knitr有一些内置的宏来防止如此大的图像溢出页面,但这意味着要调整图像的大小。我想你会发现,大约7英寸的最大宽度不应该缩小。@kohske Yep,这是完全正确的。