我正在尝试将上标放入表头中。该表稍后将用作条形图的标签。因此,我想缩写一些表格标题,并稍后在图表图例中解释缩写。
# 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)
感谢您的帮助。
最佳答案
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)
关于r - 如何在R表的表头中写入上标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60099152/