“\\n” command not working to make 2 or 3-line long figure caption using textGrob

回眸只為那壹抹淺笑 提交于 2019-12-04 20:22:06

plotmath is incompatible with newline characters, unfortunately. I'd suggest filling a table with the text split into separate lines,

library(gridExtra)
library(grid)

table_label <- function(label, params=list())  {

  params <- modifyList(list(hjust=0, x=0), params)

  mytheme <- ttheme_minimal(core = list(fg_params = params), parse=TRUE)
  disect <- strsplit(label, "\\n")[[1]]
  m <- as.matrix(disect)
  tableGrob(m, theme=mytheme)

}

txt <- 'bold("Figure 1")\nThis is another line.\n alpha~beta*" are greek letters"'
grid.newpage()

g <- table_label(txt)
grid.draw(g)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!