【问题标题】:Unable to change the global pointsize for lattice displays无法更改点阵显示的全局点大小
【发布时间】:2014-06-22 22:15:30
【问题描述】:

我需要使用 R 中的 Lattice 包生成一系列 PDF 图,其文本磅值由将在其中出版的期刊规定。

根据here, 的讨论,我可以逐个地更改点大小:

library(lattice)
trellis.device("pdf", pointsize=30)
trellis.par.set(fontsize = list(text = NULL))
xyplot(1:10 ~ 1:10)
dev.off()

这会产生以下情节:

然后我尝试设置一个全局选项:

library(lattice)
lattice.options(default.theme = list(fontsize = list(text = NULL)))
trellis.device("png", pointsize=30)
xyplot(1:10 ~ 1:10)
dev.off()

这不会产生相同的结果:

那么如何更改所有格子图的全局点大小?

【问题讨论】:

  • 怎么样:lattice.options(default.theme = list(fontsize = list(text = 30))); trellis.device("pdf"); xyplot(1:10 ~ 1:10); dev.off()?
  • 更新后能验证lattice.getOption("default.theme")的值吗?您是否尝试在重新启动 R 后运行这些行?它似乎对我有用。
  • @jbaums 这可能有效,但我使用 knits 并且需要能够为不同块中的不同图指定不同的点大小。这个想法是设置dev.args块选项具有正确的点大小,然后将其传递给pdf()
  • @MrFlick 好点。重新检查我的环境,我发现我在调用lattice.options(default.theme = canonical.theme("pdf", color = FALSE)) 后执行了上述行。然后当我调用lattice.options(default.theme = list(fontsize = list(text = NULL))) 时,我看到lattice.getOption("default.theme") 返回一个列表,其fontsize 组件没有text 元素,而不是text 元素NULL。这是 lattice 包中的错误吗?
  • 对于我(Win 8.1;R 3.1.0;RStudio 0.98.501),如果我在新会话中运行lattice.options(default.theme = list(fontsize = list(text = NULL))); trellis.device("png", pointsize=30); xyplot(1:10 ~ 1:10); dev.off(),情节类似于您的第一张图像,lattice.getOption("default.theme") 返回一个列表将fontsize$text 设置为NULL。如果我在同一个会话中第二次运行所有这些,则生成的绘图中的字体很小(根据您的第二张图像),并且lattice.getOption("default.theme") 返回一个列表,其中fontsize 设置为Named list(),如您所描述.

标签: r lattice


【解决方案1】:

jbaums 已回答您的原始问题,建议使用

library(lattice)
lattice.options(default.theme = list(fontsize = list(text = 30)))
trellis.device("pdf")
xyplot(1:10 ~ 1:10)
dev.off()

这正是你想要的:

然而,在 cmets 中,您似乎在寻求一种使用 lattice 设置默认值的方法,然后在 knitr 中使用 dev.args 传递设置。问题是trellis.device(pdf) 调用default.theme,我猜这会覆盖您提供的pointsize = 30 参数。但是,如果您想为单个格子图重置它,只需为每个单独的图调用 par.settings,如下所示:

\documentclass{article}
\begin{document}

<<setup>>=
library(lattice)
lattice.options(default.theme = list(fontsize = list(text = 8, points = 4)))
@


<<plot, dev='pdf'>>=
xyplot(1:10 ~ 1:10,
       par.settings = list(fontsize = list(text = 25)))
@


<<plot2>>=
xyplot(1:10 ~ 1:10)
@

\end{document}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-16
    • 1970-01-01
    相关资源
    最近更新 更多