我正在尝试将一个上标放到一个表格的标题中。该表稍后将用作条形图的标签。因此,我想缩写一些表标题,并在后面的图表图例中解释这些缩写。
# libraries
library(gridExtra) # for cool table
library(grid) # for cool table
# create example
df <- data.frame( a = 1:6, b = rep( letters[1:3], each = 2 ) )
# Create plotmath superscript strings
df[1,1] = paste0(df[1,1],"^",1) # i unsuccessfully tried to change the example
colnames(df)[1] <- expression('Title'^2) # here another unsuccessful try
# Define theme to parse plotmath expressions
tt = ttheme_default(core=list(fg_params=list(parse=TRUE)))
tg_df <- tableGrob(d = df, theme=tt)
grid.newpage()
grid.draw(tg_df)这给了我

谢谢你的帮助。
发布于 2020-02-07 00:20:07
在tableGrob vignette中有一个这样的例子。只需确保同时解析列标题即可
tt <- ttheme_default(
core = list(fg_params = list(parse=TRUE)),
colhead = list(fg_params = list(parse=TRUE))
)
tg_df <- tableGrob(d = df, theme=tt)
grid.newpage()
grid.draw(tg_df)

https://stackoverflow.com/questions/60099152
复制相似问题