CRAN version dependencies Monthly Downloads

basetheme

R package implementing a theming system for base plotting.

Description

The basetheme() function provides a persistent way to set and unset R plotting settings. All the user has to do is set the theme once and it will be consistenlty applied to all the subsequent plots. Even after the graphics device is closed.

Themes

Demonstration using:

pairs(iris[,1:4], col=iris$Species)
legend("bottom", legend=unique(iris$Species), col=unique(iris$Species),
       pch=par("pch"), cex=0.8, horiz=TRUE, bty="n", inset=c(0,1), xpd=TRUE
       )
default
basetheme("clean")
clean
basetheme("brutal")
brutal
basetheme("ink")
ink
basetheme("dark")
dark
basetheme("deepblue")
deepblue
basetheme("royal")
deepblue
basetheme("minimal")
minimal
basetheme("void")
void

Usage

Everything is done by calling the basetheme() function. There are 4 different modes:

  1. Choosing a theme by name
basetheme("clean")
  1. Specifying a list with theme values
theme <- basetheme("clean")
theme$cex.main <- 2

basetheme(theme)
  1. Specifying the values directly
basetheme(pch=19, bg="blue")
  1. Removing the current theme
basetheme(NULL)
  1. Obtaining list of theme parametrs
# current theme
basetheme()
# specified theme
theme <- basetheme("clean")

Additional parameters can be specified everytime. For example if you like a theme (say “minimal”) but would like to change a few parameters:

basetheme("minimal", bg="grey", pch=1)

Creating a Theme

Simplest way is to obtain a default list of values and change them.

Here is an example of creating a grey-ish sheme:

pars <- basetheme("default")
pars$palette <- c("black", grey.colors(8))  # numbered colors - shades of grey
pars$bg  <- "white"                         # some colors
pars$fg  <- "gray20"                        # some colors
pars$col <- "gray20"                        # some colors
pars$col.main <- "black"                    # some colors
pars$col.axis <- "gray20"                   # some colors
pars$col.lab  <- "gray20"                   # some colors
pars$family   <-  "mono"                    # change font
pars$lab      <-  c(10,10,7)                # more ticks on axes
pars$cex.axis <-  0.8                       # smaller axis labels
pars$las      <-  1                         # always horizontal axis labels
pars$rect.border <- "black"                 # box around the plot
pars$rect.lwd    <- 4                       # ticker border

basetheme(pars)

barplot(1:9, col=1:9, names=LETTERS[1:9], main="barplot", ylab="heights")
ex9

Installation

From CRAN:

install.packages("basetheme")

Using devtools library:

devtools::install_github("KKPMW/basetheme")

To install the developement version (stable updates not yet on CRAN):

library(devtools)
install_github("KKPMW/basetheme", ref="dev")

Details

Under the hood this library utilizes two hooks that are implemented in the plot.new() function: before.plot.new and plot.new.

See Also

Packages

CRAN:

  1. prettyB

GitHub:

  1. styles