Skip to contents

Jam default theme for ggplot2

Usage

theme_jam(
  theme_default = ggplot2::theme_bw,
  base_size = 18,
  use_rainbowJam = TRUE,
  darken_colour = FALSE,
  grid.major.size = 0.5,
  grid.minor.size = 0.25,
  strip.background.colour = "grey30",
  strip.background.fill = "lightgoldenrod1",
  strip.text.size = ggplot2::rel(14.18),
  panel.grid.major.colour = "grey80",
  panel.grid.minor.colour = "grey90",
  panel.background = ggplot2::element_rect(fill = "white", colour = NA),
  panel.border = ggplot2::element_rect(fill = NA, colour = "grey15"),
  axis.text.x.angle = 60,
  blankGrid = FALSE,
  blankXgrid = FALSE,
  blankYgrid = FALSE,
  resetTheme = TRUE,
  verbose = FALSE,
  ...
)

Arguments

theme_default

function representing a ggplot2 theme.

base_size

numeric default font point size, used for scaling the overall text sizes larger or smaller.

use_rainbowJam

logical default TRUE, whether to use colorjam for default categorical/discrete colors in ggplot2 version 4.0.0+.

darken_colour

logical default FALSE, when use_rainbowJam=TRUE it optionally darkens the 'colour' palette, useful when applying slightly darked outline color together with 'fill' color. See Examples.

grid.major.size, grid.minor.size

numeric defaults 0.5, 0.25 the line width for the major and minor grid lines, respectively. Set to 0 to suppress either, or use 'blankGrid' or 'blankXgrid' or 'blankYgrid' arguments.

strip.background.colour, strip.background.fill

character color for the border and strip background itself when ggplot2 is using a faceted layout. Default is black border and 'lightgoldenrod1' strip fill color.

strip.text.size

numeric or relative class ggplot2::rel() to define direct or relative text font size, respectively. Default is '14/18' to convert default base_size=18 to font size 14 point.

panel.grid.major.colour, panel.grid.minor.colour

character colors for the major and minor grid lines, respectively. Defaults are 'grey80' and 'grey90', respectively.

panel.background, panel.border

element_rect or NULL indicating the type of background or border to draw around each plot panel. When set to NULL it is set to ggplot2::element_blank() which displays nothing. Default uses white panel background fill with black border.

axis.text.x.angle

numeric degrees to rotate x-axis labels, default 60 degrees.Starts at 0 (horizontal) and goes counter-clockwise so that 60 show labels tilted down-left.

blankGrid, blankXgrid, blankYgrid

logical default FALSE, whether to have a blank grid for everything, major, or minor axis lines, respectively. Intended for convenience to remove gridlines.

resetTheme

logical whether to call ggplot2::theme_default which replaces all previous ggplot2 theme settings with those defined in the theme function. If FALSE then only the specific settings defined in this function will be applied.

verbose

logical indicating whether to print verbose output.

...

additional arguments are passed to ggplot2::theme(), and optionally to jam_pal() when use_rainbowJam=TRUE. Arguments are filtered to match named arguments in respective functions, by calling jamba::call_fn_ellipsis(). In other words, adding arguments to '...' should be safe even when the argument is not present in ggplot2::theme().

Details

This function applies some default theme settings to ggplot2, mainly taking away the default grey newspaper background color, also rotates the x-axis label text to 60 degrees, to accomodate longer labels without overlaps.

See also

Examples

if (jamba::check_pkg_installed("ggplot2")) {
   set.seed(123)
   dsamp <- ggplot2::diamonds[sample(nrow(ggplot2::diamonds), 1000),];
   d <- ggplot2::ggplot(dsamp,
      ggplot2::aes(carat, price)) +
      ggplot2::geom_point(
         ggplot2::aes(colour=as.character(cut)),
         size=2);
   print(d +
      scale_color_jam() +
      ggplot2::ggtitle("scale_color_jam()"));
   print(d +
      theme_jam() +
      ggplot2::ggtitle("theme_jam()"));

   d2 <- ggplot2::ggplot(dsamp,
      ggplot2::aes(carat, price)) +
      ggplot2::geom_point(
         shape="circle filled",
         ggplot2::aes(colour=as.character(cut),
            fill=as.character(cut)),
         size=2);
   print(d2 +
      theme_jam(darken_colour=TRUE) +
      ggplot2::ggtitle("theme_jam(darken_colour=TRUE)"));
}