Reputation: 1441
I'm using the geom_table()
function from the ggpmisc
package to add a table legend to my figure. I want to remove the grey colour from the first row with the column headers.
library(ggpmisc)
library(tidyverse)
mtcars %>%
group_by(cyl) %>%
summarize(wt = mean(wt), mpg = mean(mpg)) %>%
ungroup() %>%
mutate(wt = sprintf("%.2f", wt),
mpg = sprintf("%.1f", mpg)) -> tb
df <- tibble(x = 5.45, y = 34, tb = list(tb))
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
geom_point() +
geom_table(data = df, aes(x = x, y = y, label = tb),
table.theme = ttheme_gtbw)
Upvotes: 0
Views: 717
Reputation: 674
You can set the theme using arguments that are passed from ggpmisc
to the corresponding ttheme
function from gridExtra
(Description of some of the possible options). If I understand your question correctly you want the background of the first row in your table to be white. You can achieve this using the following code to build your plot:
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
geom_point() +
geom_table(data = df, aes(x = x, y = y, label = tb),
table.theme = ttheme_gtbw(colhead = list(bg_params = list(fill = "white"))))
Upvotes: 2