【问题标题】:add * or # as superscript in table using tableGrob使用 tableGrob 在表中添加 * 或 # 作为上标
【发布时间】:2017-05-03 13:26:01
【问题描述】:

如何在表格中添加*# 作为数学表达式?我问了similar question,通过在theme 参数中设置parse = TRUE 来提供解决方案。但是,当我使用 *# 等特殊字符时,它不起作用。

数据:

df <- data.frame( a = 1:6, b = rep( letters[1:3], each = 2 ) )
df$b <- paste0(df$b,"^",rep(c('*', '#'), 3))

代码:

library( 'gridExtra' )
library( 'grid' )
tt <- ttheme_default(core=list(fg_params=list(parse=TRUE)))
tg_df <- tableGrob(d = df, theme=tt)
grid.draw(tg_df)

输出:

预期:

【问题讨论】:

    标签: r gridextra


    【解决方案1】:

    你应该引用这些字符:

    library( 'gridExtra' )
    library( 'grid' )
    
    df <- data.frame( a = 1:6, b = rep( letters[1:3], each = 2 ) )
    df$b <- paste0(df$b,"^","'", rep(c('*', '#'), 3), "'")
    
    
    tt <- ttheme_default(core=list(fg_params=list(parse=TRUE)))
    tg_df <- tableGrob(d = df, theme=tt)
    grid.draw(tg_df)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-06
      相关资源
      最近更新 更多