i'm looking customise particular columns in tablegrob, reproducible example have chosen @ customising justification.
say have following dataframe:
df <- data.frame(order = c(1:3), name = c("adam", "ben", "charlie"), score = c(4, 8, 9))
and want use package gridextra
present table:
dfgrob <- tablegrob(df, rows = null) grid.arrange(dfgrob)
you can adjust alignment of columns adjusting theme used build grob, example:
tt1 <- ttheme_default(core=list(fg_params=list(hjust= 0, x=0.05)), colhead=list(fg_params=list(hjust=0, x=0.1))) dfgrob <- tablegrob(df, rows = null, theme = tt1) grid.arrange(dfgrob)
however, adjusts justification columns. want left justify order column, , leave others in central justification position, how that?
i have experimented with:
tt1 <- ttheme_default(core=list(fg_params=list(hjust= c(0, 0.5, 0.5), x=c(0.15, 0.5, 0.5))), colhead=list(fg_params=list(hjust=1, x=0.95))) dfgrob <- tablegrob(df, rows = null, theme = tt1) grid.arrange(dfgrob)
but seems customise row. how adjust code customise column instead?
it's bit fiddly can specify parameters elements,
library(grid) library(gridextra) df <- data.frame(order = c(1:3), name = c("adam", "ben", "charlie"), score = c(4, 8, 9)) hj <- matrix(c(0, 0.5, 1), ncol=3, nrow=nrow(df), byrow=true) x <- matrix(c(0, 0.5, 1), ncol=3, nrow=nrow(df), byrow=true) tt1 <- ttheme_default(core=list(fg_params=list(hjust = as.vector(hj), x = as.vector(x))), colhead=list(fg_params=list(hjust=1, x=0.95))) dfgrob <- tablegrob(df, rows = null, theme = tt1) grid.newpage() grid.draw(dfgrob)
the recycling logic defaults column wise, because table has rows of alternating colours. should possible special-case horizontal justification parameters make bit more user-friendly. feel free submit pr.
Comments
Post a Comment