inst/doc/themes.R

## ----knitr-options, echo=FALSE------------------------------------------------
library(knitr)
opts_chunk$set(
  fig.width = 6, 
  fig.height = 3
)
options(width = 80)

## ----initialise---------------------------------------------------------------
options(stringsAsFactors = FALSE)
library(ggplot2)
library(INBOtheme)

# Create a simple example dataset
pp <- function (n, r = 4){
  x <- seq(-r * pi, r * pi, len = n)
  df <- expand.grid(x = x, y = x)
  df$r <- sqrt(df$x ^ 2 + df$y ^ 2)
  df$z <- cos(df$r ^ 2) * exp(-df$r / 6)
  df
}

# Create a simple example dataset
df <- data.frame(
  trt = factor(c(1, 1, 2, 2)),
  resp = c(1, 5, 3, 4),
  group = factor(c(1, 2, 1, 2)),
  se = c(0.1, 0.3, 0.3, 0.2)
)

## ----default-theme, echo = FALSE----------------------------------------------
theme_set(theme_inbo2015(8))
switchColour(inbo.steun.geelgroen)
update_geom_defaults("text", list(size = 2.5))

## ----available-colours, fig.height=3.5----------------------------------------
palette <- data.frame(
  name = c(
    #version <= 2014
      "INBOblue", "INBOdarkblue", "INBOgreen", "INBOdarkgreen", "INBObrown",
      "INBOreddishbrown", "INBOred",
    #version >= 2015
      "inbo.hoofd", "inbo.steun.donkerroos", "inbo.steun.blauw",
      "inbo.steun.geelgroen", "inbo.oranje", "inbo.rood", "inbo.bruinrood",
      "inbo.grijs", "inbo.lichtgrijs", "inbo.grijsblauw", "inbo.lichtblauw",
      "inbo.achtergrond", "inbo.munt", "inbo.lichtgroen", "inbo.donkergroen",
      "inbo.groen", "inbo.geelgr"
  )
)
palette$x <- (seq_along(palette$name) - 1) %% ceiling(sqrt(nrow(palette)))
palette$y <- (seq_along(palette$name) - 1) %/% ceiling(sqrt(nrow(palette)))
palette$colour <- sapply(
  palette$name,
  function(i){
    eval(parse(text = i))
  }
)
rownames(palette) <- palette$name
palette$name <- factor(palette$name, levels = palette$name)
ggplot(palette, aes(x = x, y = y, label = name, fill = name)) +
  geom_tile() + geom_text() +
  scale_fill_manual(
    values = palette$colour,
    guide = guide_legend(ncol = 3)
  ) +
  ggtitle("All available named colours in the INBOtheme package")

## ----INBO-palettes------------------------------------------------------------
# version >= 2015
n <- 16
inbo.2015.colours(n = n)
palette <- data.frame(n = seq_len(n))
palette$row <- (palette$n - 1) %/% ceiling(sqrt(n))
palette$col <- (palette$n - 1) %% ceiling(sqrt(n))
ggplot(palette, aes(x = col, y = row, fill = factor(n))) +
  geom_tile() +
  geom_text(aes(label = n), colour = "black") +
  scale_fill_manual(values = inbo.2015.colours(n = n), guide = "none")
# version <= 2014
n <- 16
INBO.colours(n = n)
palette <- data.frame(n = seq_len(n))
palette$row <- (palette$n - 1) %/% ceiling(sqrt(n))
palette$col <- (palette$n - 1) %% ceiling(sqrt(n))
ggplot(palette, aes(x = col, y = row, fill = factor(n))) +
  geom_tile() +
  geom_text(aes(label = n), colour = "black") +
  scale_fill_manual(values = INBO.colours(n = n), guide = "none")

## ----set-theme-INBO2015-------------------------------------------------------
theme_set(theme_inbo2015(8))
switchColour(inbo.steun.geelgroen)

## ----different-figures--------------------------------------------------------
ggplot(movies, aes(x = rating)) +
  geom_histogram()
ggplot(movies, aes(x = rating)) +
  geom_histogram() +
  facet_wrap(~mpaa, scales = "free")
ggplot(movies, aes(x = rating)) +
  geom_histogram(aes(fill = ..count..)) +
  facet_grid(Comedy ~ Drama, scales = "free") + 
  scale_fill_gradient()
ggplot(movies, aes(x = rating)) +
  geom_histogram(aes(fill = ..count..)) +
  scale_fill_gradient()
ggplot(diamonds, aes(x = carat, y = depth, colour = price)) +
  geom_point() +
  scale_colour_gradient()
selection <- table(msleep$order)
selection <- names(selection)[selection > 3]
ggplot(
  subset(msleep, order %in% selection), 
  aes(x = bodywt, y = sleep_total, label = name)
) + 
  geom_point() + 
  geom_text() + 
  facet_wrap(~order, scales = "free") + 
  scale_x_continuous(expand = c(0.5, 0.01))
ggplot(diamonds, aes(x = price, fill = cut)) +
  geom_histogram()
ggplot(diamonds, aes(x = log10(price), fill = cut)) +
  geom_histogram() +
  facet_wrap(~ clarity)
ggplot(diamonds, aes(x = price, colour = cut)) +
  geom_density()
ggplot(diamonds, aes(x = price, fill = cut)) +
  geom_density(alpha = 0.2)
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(cyl), fill = factor(cyl))) +
  geom_point() + 
  geom_smooth(method = "lm")
ggplot(pp(100), aes(x = x, y = y, fill = z)) +
  geom_tile() +
  scale_fill_gradient()
ggplot(
  df,
  aes(colour = group, y = resp, x = trt, ymax = resp + se, ymin = resp - se)
) +
  geom_point() +
  geom_errorbar(width = 0.2)

## ----set-theme-INBO-----------------------------------------------------------
theme_set(theme_INBO(8))
switchColour(INBObrown)

## ----figure-INBO--------------------------------------------------------------
ggplot(movies, aes(x = rating)) +
  geom_histogram()
ggplot(movies, aes(x = rating)) +
  geom_histogram() +
  facet_wrap(~mpaa, scales = "free")
ggplot(movies, aes(x = rating)) +
  geom_histogram(aes(fill = ..count..)) +
  facet_grid(Comedy ~ Drama, scales = "free") + 
  scale_fill_gradient()
ggplot(movies, aes(x = rating)) +
  geom_histogram(aes(fill = ..count..)) +
  scale_fill_gradient()
ggplot(diamonds, aes(x = carat, y = depth, colour = price)) +
  geom_point() +
  scale_colour_gradient()
selection <- table(msleep$order)
selection <- names(selection)[selection > 3]
ggplot(
  subset(msleep, order %in% selection), 
  aes(x = bodywt, y = sleep_total, label = name)
) + 
  geom_point() + 
  geom_text() + 
  facet_wrap(~order, scales = "free") + 
  scale_x_continuous(expand = c(0.5, 0.01))
ggplot(diamonds, aes(x = price, fill = cut)) +
  geom_histogram()
ggplot(diamonds, aes(x = log10(price), fill = cut)) +
  geom_histogram() +
  facet_wrap(~ clarity)
ggplot(diamonds, aes(x = price, colour = cut)) +
  geom_density()
ggplot(diamonds, aes(x = price, fill = cut)) +
  geom_density(alpha = 0.2)
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(cyl), fill = factor(cyl))) +
  geom_point() + 
  geom_smooth(method = "lm")
ggplot(pp(100), aes(x = x, y = y, fill = z)) +
  geom_tile() +
  scale_fill_gradient()
ggplot(
  df,
  aes(colour = group, y = resp, x = trt, ymax = resp + se, ymin = resp - se)
) +
  geom_point() +
  geom_errorbar(width = 0.2)

## ----set-theme-elsevier-------------------------------------------------------
theme_set(theme_elsevier(8))
switchColour("black")

## ----figure-elsevier----------------------------------------------------------
ggplot(movies, aes(x = rating)) +
  geom_histogram()
ggplot(movies, aes(x = rating)) +
  geom_histogram() +
  facet_wrap(~mpaa, scales = "free")
ggplot(movies, aes(x = rating)) +
  geom_histogram(aes(fill = ..count..)) +
  facet_grid(Comedy ~ Drama, scales = "free") + 
  scale_fill_gradient()
ggplot(movies, aes(x = rating)) +
  geom_histogram(aes(fill = ..count..)) +
  scale_fill_gradient()
ggplot(diamonds, aes(x = carat, y = depth, colour = price)) +
  geom_point() +
  scale_colour_gradient()
selection <- table(msleep$order)
selection <- names(selection)[selection > 3]
ggplot(
  subset(msleep, order %in% selection), 
  aes(x = bodywt, y = sleep_total, label = name)
) + 
  geom_point() + 
  geom_text() + 
  facet_wrap(~order, scales = "free") + 
  scale_x_continuous(expand = c(0.5, 0.01))
ggplot(diamonds, aes(x = price, fill = cut)) +
  geom_histogram()
ggplot(diamonds, aes(x = log10(price), fill = cut)) +
  geom_histogram() +
  facet_wrap(~ clarity)
ggplot(diamonds, aes(x = price, colour = cut)) +
  geom_density()
ggplot(diamonds, aes(x = price, fill = cut)) +
  geom_density(alpha = 0.2)
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(cyl), fill = factor(cyl))) +
  geom_point() + 
  geom_smooth(method = "lm")
ggplot(pp(100), aes(x = x, y = y, fill = z)) +
  geom_tile() +
  scale_fill_gradient()
ggplot(
  df,
  aes(colour = group, y = resp, x = trt, ymax = resp + se, ymin = resp - se)
) +
  geom_point() +
  geom_errorbar(width = 0.2)

Try the INBOtheme package in your browser

Any scripts or data that you put into this service are public.

INBOtheme documentation built on May 2, 2019, 5:25 p.m.