首页 > 解决方案 > 在 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'

标签: rggplot2

解决方案


推荐阅读