## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment  = "#>",
  fig.width  = 6,
  fig.height = 4,
  dpi = 110
)

## -----------------------------------------------------------------------------
library(ggplot2)
library(ggsketch)

## ----first-bar----------------------------------------------------------------
df <- data.frame(product = c("Alpha", "Bravo", "Charlie", "Delta"),
                 units   = c(34, 51, 22, 47))

ggplot(df, aes(product, units)) +
  geom_sketch_col(fill = "#7BAFD4", seed = 1L) +
  labs(title = "Units sold") +
  theme_sketch()

## ----seeds, fig.height=2.6----------------------------------------------------
base <- ggplot(df, aes(product, units)) + theme_sketch()
base + geom_sketch_col(seed = 1L) + labs(subtitle = "seed = 1")
base + geom_sketch_col(seed = 7L) + labs(subtitle = "seed = 7")

## ----roughness----------------------------------------------------------------
x <- seq(0, 10, length.out = 40)
d <- data.frame(x = x, y = sin(x))

ggplot(d, aes(x, y)) +
  geom_sketch_line(aes(colour = "0.0"), roughness = 0,   seed = 2) +
  geom_sketch_line(aes(colour = "1.5"), roughness = 1.5, seed = 2) +
  geom_sketch_line(aes(colour = "4.0"), roughness = 4,   seed = 2) +
  scale_colour_brewer("roughness", palette = "Set1") +
  theme_sketch()

## ----fill-one-----------------------------------------------------------------
bars <- data.frame(x = c("A", "B", "C"), y = c(4, 6, 3))
ggplot(bars, aes(x, y)) +
  geom_sketch_col(fill = "#E8A87C", fill_style = "cross_hatch", seed = 4) +
  labs(title = "cross_hatch") +
  theme_sketch()

## ----compose------------------------------------------------------------------
ggplot(mtcars, aes(wt, mpg)) +
  geom_sketch_point(size = 2.5, colour = "#34495E", seed = 9) +
  geom_sketch_smooth(method = "lm", formula = y ~ x, seed = 10) +
  facet_wrap(~am, labeller = label_both) +
  theme_sketch()

## ----annotate-----------------------------------------------------------------
ggplot(mtcars, aes(wt, mpg)) +
  geom_sketch_point(colour = "#E8E6DF", seed = 1L) +
  annotate_sketch("rect", xmin = 3, xmax = 4, ymin = 15, ymax = 22,
                  fill = NA, colour = "#FFD166", seed = 2L) +
  theme_sketch(dark = TRUE)

