Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggtexttable: how to select single cell #29

Closed
tsenoner opened this issue Aug 27, 2017 · 2 comments
Closed

ggtexttable: how to select single cell #29

tsenoner opened this issue Aug 27, 2017 · 2 comments

Comments

@tsenoner
Copy link

Is it possible to access a single cell in a table output? And then change e.g. the background or the font?
Like you can do with the grid and gridExtra package?
Here is an example how it would be done with these packages:

library(gridExtra)
library(grid)
g <- tableGrob(iris[1:4, 1:3])
find_cell <- function(table, row, col, name="core-fg"){
  l <- table$layout
  which(l$t==row & l$l==col & l$name==name)
}

ind <- find_cell(g, 3, 2, "core-fg")
ind2 <- find_cell(g, 2, 3, "core-bg")
g$grobs[ind][[1]][["gp"]] <- gpar(fontsize=15, fontface="bold")
g$grobs[ind2][[1]][["gp"]] <- gpar(fill="darkolivegreen1", col = "darkolivegreen4", lwd=5)
grid.draw(g)
@kassambara
Copy link
Owner

New functions table_cell_font() and table_cell_bg() added to easily access and change the text font and the background of ggtexttable() cells

# Access and modify the font and 
# the background of table cells
# :::::::::::::::::::::::::::::::::::::::::::::
library(ggpubr)
tab <- ggtexttable(head(iris), rows = NULL,
                  theme = ttheme("classic"))
tab <- table_cell_font(tab, row = 3, column = 2, 
                       face = "bold")
tab <- table_cell_bg(tab, row = 4, column = 3, linewidth = 5,
                    fill="darkolivegreen1", color = "darkolivegreen4")
tab

rplot17

@tsenoner
Copy link
Author

Wow thanks!!
That is what I was looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants