Learn R Programming

ggpp (version 0.5.9)

ttheme_gtdefault: Table themes

Description

Additional theme constructors for use with geom_table.

Usage

ttheme_gtdefault(
  base_size = 10,
  base_colour = "black",
  base_family = "",
  parse = FALSE,
  padding = grid::unit(c(0.8, 0.6), "char"),
  text.alpha = NA,
  rules.alpha = NA,
  canvas.alpha = NA,
  ...
)

ttheme_gtminimal( base_size = 10, base_colour = "black", base_family = "", parse = FALSE, padding = grid::unit(c(0.5, 0.4), "char"), text.alpha = NA, rules.alpha = NA, canvas.alpha = NA, ... )

ttheme_gtbw( base_size = 10, base_colour = "black", base_family = "", parse = FALSE, padding = grid::unit(c(1, 0.6), "char"), text.alpha = NA, rules.alpha = NA, canvas.alpha = NA, ... )

ttheme_gtplain( base_size = 10, base_colour = "black", base_family = "", parse = FALSE, padding = grid::unit(c(0.8, 0.6), "char"), text.alpha = NA, rules.alpha = NA, canvas.alpha = NA, ... )

ttheme_gtdark( base_size = 10, base_colour = "grey90", base_family = "", parse = FALSE, padding = grid::unit(c(0.8, 0.6), "char"), text.alpha = NA, rules.alpha = NA, canvas.alpha = NA, ... )

ttheme_gtlight( base_size = 10, base_colour = "grey10", base_family = "", parse = FALSE, padding = grid::unit(c(0.8, 0.6), "char"), text.alpha = NA, rules.alpha = NA, canvas.alpha = NA, ... )

ttheme_gtsimple( base_size = 10, base_colour = "grey10", base_family = "", parse = FALSE, padding = grid::unit(c(0.5, 0.4), "char"), text.alpha = NA, rules.alpha = NA, canvas.alpha = NA, ... )

ttheme_gtstripes( base_size = 10, base_colour = "grey10", base_family = "", parse = FALSE, padding = grid::unit(c(0.8, 0.6), "char"), text.alpha = NA, rules.alpha = NA, canvas.alpha = NA, ... )

Value

A list object that can be used as ttheme in the construction of tables with functions from package 'gridExtra'.

Arguments

base_size

numeric, default font size of text in table.

base_colour

default font colour for text in table.

base_family

default font family for text in table.

parse

logical, behaviour for parsing text as plotmath.

padding

length-2 unit vector specifying the horizontal and vertical padding of text within each cell.

text.alpha, canvas.alpha, rules.alpha

numeric in [0..1] Transparency applied to table base_colour, to table body background fill and rules colour, respectively.

...

further arguments to control the gtable.

Details

These wrapper functions are table theme (ttheme) constructors making it easier to change the style of tables created with tableGrob. When passed as argument to geom_table the table theme's base_colour, base_family, base_colour and base_size function as defaults for the text in the body of the table. They are overriden if the corresponding text-related aesthetics are mapped or set to a constant through the usual 'ggplot2' mechanisms. On the other hand the properties of the background fill, rules and column and row headings can be set only through the theme. The ttheme constructors defined in 'ggpp' have formal parameters for alpha transparency of the text, background and rules. Transparency is useful as plot insets can accidentally overlap observations hiding them from view depending on the stacking order of plot layers.

These theme constructors are wrappers on the constructors gridExtra::ttheme_default() and gridExtra::ttheme_minimal(). They can also be used directly with grid.table if desired.

Examples

Run this code
library(dplyr)
library(tibble)

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))

# Same as the default theme constructor
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
  geom_point() +
  geom_table(data = df, aes(x = x, y = y, label = tb),
             table.theme = ttheme_gtdefault) +
  theme_classic()

# Minimal theme constructor
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
  geom_point() +
  geom_table(data = df, aes(x = x, y = y, label = tb),
             table.theme = ttheme_gtminimal) +
  theme_classic()

# A theme with white background
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) +
  theme_bw()

# Base colour of theme overridden by aesthetic constant
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, colour = "darkblue") +
  theme_bw()

# A theme with dark background
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
  geom_point() +
  geom_table(data = df, aes(x = x, y = y, label = tb),
             table.theme = ttheme_gtdark) +
  theme_dark()

# Base colour of theme overridden by aesthetic constant
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
  geom_point() +
  geom_table(data = df, aes(x = x, y = y, label = tb),
             table.theme = ttheme_gtdark, colour = "yellow") +
  theme_dark()

# A theme with light background
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
  geom_point() +
  geom_table(data = df, aes(x = x, y = y, label = tb),
             table.theme = ttheme_gtlight)

# Base colour of theme overridden by aesthetic constant
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
  geom_point() +
  geom_table(data = df, aes(x = x, y = y, label = tb),
             table.theme = ttheme_gtlight, colour = "darkred")

# Base colour of theme overridden by aesthetic constant
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
  geom_point() +
  geom_table(data = df, aes(x = x, y = y, label = tb),
             table.theme = ttheme_gtsimple)

# Default colour of theme superceded by aesthetic constant
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
  geom_point() +
  geom_table(data = df, aes(x = x, y = y, label = tb),
             table.theme = ttheme_gtstripes) +
  theme_dark()

# Transparency of table background fill and grid lines colour
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
  geom_point() +
  geom_table(data = df, aes(x = 1.5, y = y, label = tb),
             table.theme = ttheme_gtplain(canvas.alpha = 0.5,
                                          rules.alpha = 0.2)) +
  theme_classic()

# Transparency of table background fill and grid lines colour
# and table text base colour: black with 50% transparency
ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) +
  geom_point() +
  geom_table(data = df, aes(x = 1.5, y = y, label = tb),
             table.theme = ttheme_gtplain(text.alpha = 0.5)) +
  theme_classic()

Run the code above in your browser using DataLab