Themes for base plotting system in R

Themes for base plotting system in R

This is my note for learning Themes for base plotting system in R.

basetheme package is a magic package, which let you love R’s base plotting system again!

Usage

R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
library(basetheme)
basetheme(pch = 19, mgp = c(2, 0.7, 0), tck = -0.01)
# Choosing a theme by name:
basetheme("clean")
# Using a mix of the above
basetheme("minimal", bg = "grey", pch = 1)
# Specifying a list with theme values
theme <- basetheme("clean")
theme$cex.main <- 2
basetheme(theme)
# Obtaining a list of parameters for the current theme:
basetheme()
# Removing the current theme:
basetheme(NULL)

Some examples

R
1
2
basetheme("void")
boxplot(split(iris$Sepal.Width, iris$Species))

R
1
2
basetheme("clean")
barplot(rivers, col = num2col(rivers))

R
1
2
basetheme("brutal")
plot(hclust(dist(USArrests), "ward.D2"), hang = -1)

R
1
2
basetheme("royal")
pairs(iris[-5], bg = lab2col(iris$Species), col = 0)

R
1
2
basetheme("deepblue")
pairs(iris[-5], bg = num2col(iris[,1]), col = 0)

R
1
2
3
4
5
x <- seq(-1.95, 1.95, length.out = 30)
y <- seq(-1.95, 1.95, length.out = 35)
z <- outer(x, y, function(a, b) a * b ^ 2)
basetheme("dark")
persp(x, y, z, theta = -45)

List of Available Themes

R
1
2
3
4
5
6
7
8
9
10
11
basetheme(NULL)
pairs(iris[, 1:4], col = lab2col(iris$Species))
legend("bottom",
legend = unique(iris$Species),
col = lab2col(unique(iris$Species)),
pch = par("pch"),
cex = 0.8,
horiz = TRUE,
bty = "n",
inset = c(0, 1),
xpd = TRUE)

R
1
2
3
4
5
6
7
8
9
10
11
basetheme("clean")
pairs(iris[, 1:4], col = lab2col(iris$Species))
legend("bottom",
legend = unique(iris$Species),
col = lab2col(unique(iris$Species)),
pch = par("pch"),
cex = 0.8,
horiz = TRUE,
bty = "n",
inset = c(0, 1),
xpd = TRUE)

R
1
2
3
4
5
6
7
8
9
10
11
basetheme("brutal")
pairs(iris[, 1:4], col = lab2col(iris$Species))
legend("bottom",
legend = unique(iris$Species),
col = lab2col(unique(iris$Species)),
pch = par("pch"),
cex = 0.8,
horiz = TRUE,
bty = "n",
inset = c(0, 1),
xpd = TRUE)

R
1
2
3
4
5
6
7
8
9
10
11
basetheme("ink")
pairs(iris[, 1:4], col = lab2col(iris$Species))
legend("bottom",
legend = unique(iris$Species),
col = lab2col(unique(iris$Species)),
pch = par("pch"),
cex = 0.8,
horiz = TRUE,
bty = "n",
inset = c(0, 1),
xpd = TRUE)

R
1
2
3
4
5
6
7
8
9
10
11
basetheme("dark")
pairs(iris[, 1:4], col = lab2col(iris$Species))
legend("bottom",
legend = unique(iris$Species),
col = lab2col(unique(iris$Species)),
pch = par("pch"),
cex = 0.8,
horiz = TRUE,
bty = "n",
inset = c(0, 1),
xpd = TRUE)

R
1
2
3
4
5
6
7
8
9
10
11
basetheme("deepblue")
pairs(iris[, 1:4], col = lab2col(iris$Species))
legend("bottom",
legend = unique(iris$Species),
col = lab2col(unique(iris$Species)),
pch = par("pch"),
cex = 0.8,
horiz = TRUE,
bty = "n",
inset = c(0, 1),
xpd = TRUE)

R
1
2
3
4
5
6
7
8
9
10
11
basetheme("royal")
pairs(iris[, 1:4], col = lab2col(iris$Species))
legend("bottom",
legend = unique(iris$Species),
col = lab2col(unique(iris$Species)),
pch = par("pch"),
cex = 0.8,
horiz = TRUE,
bty = "n",
inset = c(0, 1),
xpd = TRUE)

R
1
2
3
4
5
6
7
8
9
10
11
basetheme("minimal")
pairs(iris[, 1:4], col = lab2col(iris$Species))
legend("bottom",
legend = unique(iris$Species),
col = lab2col(unique(iris$Species)),
pch = par("pch"),
cex = 0.8,
horiz = TRUE,
bty = "n",
inset = c(0, 1),
xpd = TRUE)

R
1
2
3
4
5
6
7
8
9
10
11
basetheme("void")
pairs(iris[, 1:4], col = lab2col(iris$Species))
legend("bottom",
legend = unique(iris$Species),
col = lab2col(unique(iris$Species)),
pch = par("pch"),
cex = 0.8,
horiz = TRUE,
bty = "n",
inset = c(0, 1),
xpd = TRUE)

Creating Custom Themes

R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
pars <- basetheme("default")
pars$palette <- ggrapid::select_palette() # 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 <- "CascadiaCode-Regular" # 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")

# R

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×