【问题标题】:How to specify font sizes in plots with multiple plots per page?如何在每页有多个绘图的绘图中指定字体大小?
【发布时间】:2015-07-04 10:45:27
【问题描述】:

当我在 RStudio 中使用 knitr 生成 .pdf 文件时,单个图会显示轴标签、图例等所需的字体大小。但是,当我使用 layout() 函数生成多个子图时,这些字体尺寸减小。请看下面的示例代码。

\documentclass[12pt,english,twocolumn]{article}
\begin{document}
<<settings, message=FALSE, echo=FALSE, cache=FALSE>>=
# set tikz default options
opts_chunk$set(
  out.width='15cm',
  fig.width=5.906, # inch
  fig.height=5.906, # inch
  dev='tikz',
  fig.align='center',
  fig.lp='fig:',
  fig.env='figure*',
  dev.args=list(pointsize=10),
  message=FALSE, 
  echo=FALSE
)
options(tikzDefaultEngine = "pdftex")
@
<<singlePlot, fig.cap="single plot with good font size">>=
par(cex=1)
plot(rnorm(100))
@
<<multiplePlots, fig.cap="multiple plots with fonts being too small">>=
par(cex=1)
layout(matrix(1:9, 3))
for(i in 1:9) plot(rnorm(100))
@
\end{document}

如何使第二个图中的字体与第一个图中的字体大小相同?谢谢!

【问题讨论】:

    标签: r knitr


    【解决方案1】:

    哦,天哪,我在发布问题后仅 30 秒就自己想通了...

    诀窍是在第二个图中颠倒 layout() 和 par() 的顺序,如下所示:

    <<multiplePlots, fig.cap="multiple plots with fonts being just right">>=
    layout(matrix(1:9, 3))
    par(cex=1)
    for(i in 1:9) plot(rnorm(100))
    @
    

    这按预期工作。

    所以在设置多个绘图时,layout() 似乎在内部调用 par() 以设置新的(较小的)字符扩展值。因此在布局之前设置 par(cex=1) 没有效果。我不知道这一点,但这是有道理的。抱歉造成不必要的打扰。

    【讨论】:

    • 嗨@UncertainVagery,如果你意识到你的错误,你可以删除你的问题,或者当接受你自己答案的时间限制过去时(我想可能是四个小时?),接受这个答案。
    • 感谢您指出这一点。一旦时间过去,我将接受它作为答案(系统显示“等待 2 天”)。也许我将来会再次遇到同样的问题,然后找到我自己的答案;)
    猜你喜欢
    • 2011-11-11
    • 2020-12-12
    • 1970-01-01
    • 2016-12-04
    • 2018-05-13
    • 2012-07-10
    • 2011-05-13
    相关资源
    最近更新 更多