r - 在 grid.arrange 中使用 tex 表达式
问题描述
我正在构建几个ggplot
对象并将它们保存到一个列表中,以显示它们我使用grid.arrange
,这里是一个例子:
chain = matrix(rnorm(1000), nrow=100)
numParams = ncol(chain)
plots = list()
for (col in 1:numParams) local({
hist = ggplot() + geom_density(mapping = aes_(chain[, col]))
plots[[col]] <<- hist + labs(x="", y="")
})
title = "A title"
do.call("grid.arrange", c(plots, nrow=numParams, top=title))
到目前为止一切正常,但是我希望使用latex2exp
乳胶表达式作为标题,例如
title = TeX("values $\\lambda$")
使用它会给我以下错误
do.call("grid.arrange", c(plots, nrow = numRow, top = title)) 中的错误:第二个参数必须是一个列表
这是因为c(plots, nrow=numParams, top=title)
, whentitle
是一个表达式,返回一个表达式。
有没有人知道如何解决这个问题?
编辑 1:一些变体和错误
do.call("grid.arrange", list(plots, nrow=2, top=title))
给出错误:
gList(list(nrow = list(data = list(), layers = list(, : "gList" 中只允许“grobs”) 中的错误
plots["nrow"] = 2
plots["top"] = title
do.call("grid.arrange", plots)
给出错误:
粘贴错误(“值”,“”,lambda,,,,,“”):找不到对象'lambda'
解决方案
推荐阅读
- node.js - Mongoose - model.find({}) 有效,但 model.findOne({}) 无效
- python - 当列表包含类对象的元素时如何应用地图功能?
- c# - 单独关闭 WPF 窗口以使用 X 按钮从喊叫应用程序创建新窗口
- powershell - powershell 在 azure repo 中迭代文件
- node.js - 如何更新/编辑现有的帖子/交易?
- javascript - 如何从带有 JSON 文件的 python 将此表单提交到指定的网站?
- django - 我想显示目录(图像)中的随机图像并在 Django 中的模板中显示
- laravel - 图片上传(移动)在 laravel 上不起作用
- python - 在训练期间评估模型会影响其性能 PyTorch
- javascript - 打字稿编译器未将“this”转换为“_this”