Sathish
Sathish

Reputation: 12703

add * or # as superscript in table using tableGrob

How to add * or # as math expression in the table? I asked a similar question where the solution was offered by setting parse = TRUE in theme parameters. However, it does not work when I use special characters like * or #.

Data:

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

Code:

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)

Output:

enter image description here

Expected:

enter image description here

Upvotes: 0

Views: 353

Answers (1)

mt1022
mt1022

Reputation: 17289

You should quote those characters:

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)

Upvotes: 2

Related Questions