Learn R Programming

sjPlot (version 2.0.0)

sjp.setTheme: Set global theme options for sjp-functions

Description

Set global theme options for sjp-functions.

Usage

sjp.setTheme(theme = NULL, title.color = "black", title.size = 1.2,
  title.align = "left", geom.outline.color = NULL, geom.outline.size = 0,
  geom.boxoutline.size = 0.5, geom.boxoutline.color = "black",
  geom.alpha = 1, geom.linetype = 1, geom.errorbar.size = 0.7,
  geom.errorbar.linetype = 1, geom.label.color = NULL,
  geom.label.size = 4, geom.label.alpha = 1, geom.label.angle = 0,
  axis.title.color = "grey30", axis.title.size = 1.1, axis.angle.x = 0,
  axis.angle.y = 0, axis.angle = NULL, axis.textcolor.x = "grey30",
  axis.textcolor.y = "grey30", axis.textcolor = NULL,
  axis.linecolor.x = NULL, axis.linecolor.y = NULL, axis.linecolor = NULL,
  axis.line.size = 0.5, axis.textsize.x = 1, axis.textsize.y = 1,
  axis.textsize = NULL, axis.tickslen = NULL, axis.tickscol = NULL,
  axis.ticksmar = NULL, axis.ticksize.x = NULL, axis.ticksize.y = NULL,
  panel.backcol = NULL, panel.bordercol = NULL, panel.col = NULL,
  panel.major.gridcol = NULL, panel.minor.gridcol = NULL,
  panel.gridcol = NULL, panel.major.linetype = 1,
  panel.minor.linetype = 1, plot.backcol = NULL, plot.bordercol = NULL,
  plot.col = NULL, legend.pos = "right", legend.just = NULL,
  legend.inside = FALSE, legend.size = 1, legend.color = "black",
  legend.title.size = 1, legend.title.color = "black",
  legend.title.face = "bold", legend.backgroundcol = "white",
  legend.bordercol = "white", legend.item.size = NULL,
  legend.item.backcol = "grey90", legend.item.bordercol = "white",
  base = theme_grey())

Arguments

Value

The customized theme object, or NULL, if a ggplot-theme was used.

Details

If the theme argument is one of the valid ggplot-themes, this theme will be used and all further arguments will be ignored. If you want to modify a ggplot-theme, use base = "theme_xy", then further arguments to this function will be applied to the theme as well. If the theme argument is one of sjPlot-pre-set-themes, you can use further arguments for specific customization of the theme. sjPlot-pre-set-themes won't work with the base argument! The base argument is only intended to select a ggplot-theme as base for further modifications (which can be triggered via the various function arguments).

References

  • http://zevross.com/blog/2014/08/04/beautiful-plotting-in-r-a-ggplot2-cheatsheet-3/{Beautiful plotting in R: A ggplot2 cheatsheet}
  • http://minimaxir.com/2015/02/ggplot-tutorial/{An Introduction on How to Make Beautiful Charts With R and ggplot2}

See Also

http://www.strengejacke.de/sjPlot/custplot/{sjPlot manual: customize plot appearance}

Examples

Run this code
library(sjmisc)
data(efc)
# set sjPlot-defaults, a slightly modification
# of the ggplot base theme
sjp.setTheme()

# legends of all plots inside
sjp.setTheme(legend.pos = "top left", 
             legend.inside = TRUE)
sjp.xtab(efc$e42dep, efc$e16sex)

# Use classic-theme. you may need to
# load the ggplot2-library.
library(ggplot2)
sjp.setTheme(theme = theme_classic())
sjp.frq(efc$e42dep)

# adjust value labels
sjp.setTheme(geom.label.size = 3.5, geom.label.color = "#3366cc",
             geom.label.angle = 90)
# hjust-aes needs adjustment for this
update_geom_defaults('text', list(hjust = -0.1))
sjp.xtab(efc$e42dep, efc$e16sex, vjust = "center", hjust = "center")

# Create own theme based on classic-theme
sjp.setTheme(base = theme_classic(), axis.linecolor = "grey50",
             axis.textcolor = "#6699cc")
sjp.frq(efc$e42dep)

# use theme pre-set
sjp.setTheme(theme = "538", geom.alpha = 0.8)
library(ggplot2) # for custom base-line
sjp.frq(efc$e42dep, geom.color = "#c0392b", expand.grid = TRUE,
        prnt.plot = FALSE)$plot + 
  geom_hline(yintercept = 0, size = 0.5, colour = "black")

# mimic R base theme
sjp.setTheme("rbase")
sjp.frq(efc$e42dep, ylim = c(0, 400), axis.title = "", 
        title = get_label(efc$e42dep))

Run the code above in your browser using DataLab