knitr::opts_chunk$set(echo = TRUE, message = F, warning = F, fig.height = 6, comment = "")
options(knitr.duplicate.label = "allow")
library(ggstamp)

r flipbookr::chunk_reveal('ggbackdrop_1', title = '### ggbackdrop')

# voiding grid
last_plot() +
   theme_void()

r flipbookr::chunk_reveal('ggbackdrop_2', title = '### ggbackdrop')

library(ggplot2)
ggbackdrop() +
stamp_curve(curvature = .3, yend = 75, xend = 100) +
stamp_polygon(x0 = 20, y0 = 60, radius = 20, alpha = .4) +
stamp_text(x = 20, y = 60, label = "{ggstamp}",
           size = 5, color = "grey97")

r flipbookr::chunk_reveal('ggcanvas_3', title = '### ggcanvas')

library(ggplot2)
ggcanvas() +
  stamp_point(color = "plum4") +
  stamp_point(x = 1, y = 1,
              color = "lightsteelblue3",
              size = 35) +
  stamp_arrow(color = "plum4",
              headlength = .06,
              type = "closed") +
  stamp_label(1.5, 2.5, label = "      nnnnn",
              size = 15,
              fill = "lemonchiffon", ) +
  stamp_circle(2.5, 1.25,
               fill = "plum4") +
  stamp_point(x = c(2,2:4), y = 1:4,
              color = "paleturquoise",
              size = 15) +
  stamp_arrow(y = 2, yend = 1:4,
              xend = c(2,2:4),
              color = "cadetblue4") +
  stamp_label(1, 3.5, label = "Stamps!",
              fill = "paleturquoise3") +
  stamp_label(3.2, 1.75, label = "Umm...  n         ",
              size = 18,
              fill = "thistle") +
  stamp_label(3.2, 1.75, label = "Umm...  n Stamps!",
              size = 18,
              fill = "thistle") +
  theme_void() +
  stamp_curve(x = .25 + log(1:12),
              xend = 1.5 + sqrt(1:12),
              y = 0 + 1:12/20,
              color = "palegreen3",
              yend = 1:12/6,
              curvature = -.1,
              alpha = 12:1/12)

r flipbookr::chunk_reveal('ggdraft_4', title = '### ggdraft')

# remove drafting lines
(ggdraft() +
stamp_polygon(x0 = 20, y0 = 40,
              radius = 20, alpha = .4) +
stamp_polygon(x0 = 85, y0 = 23,
              radius = 22,
              n = 5, fill = "seagreen2")
   ) +
theme_void()

r flipbookr::chunk_reveal('ggdraft_5', title = '### ggdraft')

library(ggplot2)
ggdraft() +
stamp_curve(curvature = .13,
            size = .09,
            yend = 20:60,
            xend = 100) +
stamp_polygon(x0 = 20, y0 = 40,
              radius = 20, alpha = .4) +
stamp_text(x = 20, y = 40, label = "{ggstamp}",
           size = 6, color = "grey97")

r flipbookr::chunk_reveal('pos_honeycomb_x_6', title = '### pos_honeycomb_x')

pos_honeycomb_x()
pos_honeycomb_x(n = 10, x0 = 5, ncol = 2)

r flipbookr::chunk_reveal('pos_honeycomb_y_7', title = '### pos_honeycomb_y')

pos_honeycomb_y()
ggcanvas() +
 stamp_polygon(x0 = pos_honeycomb_x(),
               y0 = pos_honeycomb_y())

r flipbookr::chunk_reveal('pos_honeycomb_8', title = '### pos_honeycomb')

# a hive
ggcanvas() +
  stamp_polygon(x0y0 = pos_honeycomb(width = 1.8),
                fill = c("goldenrod3"),
                alpha = .8,
                size = 0)  +
  stamp_polygon(x0y0 = pos_honeycomb(width = 1.8, n = 12)[c(6:9, 11),],
                fill = c("goldenrod4"),
                alpha = .8,
                size = 0) +
  stamp_polygon(x0y0 = pos_honeycomb(width = 1.8, n = 15)[c(10,12:15),],
                fill = c("goldenrod2"),
                alpha = .8,
                size = 0) +
  stamp_png(x0y0 = pos_honeycomb(width = 1.8, n = 15)[c(1,5, 10),])

r flipbookr::chunk_reveal('pos_honeycomb_9', title = '### pos_honeycomb')

# first example
pos_honeycomb()
ggcanvas() +
 stamp_point(xy = pos_honeycomb()) +
 stamp_polygon(x0y0 = pos_honeycomb(n = 15, ncol = 4),
     alpha = .5) +
 stamp_label(label = 1:15, xy = pos_honeycomb(n = 15, ncol = 4)) +
 stamp_polygon(n = 4,
               x0y0 = pos_honeycomb(n = 15, ncol = 4)[15,],
               fill = "magenta", alpha = .4, radius = sqrt(.75))

r flipbookr::chunk_reveal('pos_honeycomb_10', title = '### pos_honeycomb')

# get coords for single position
pos_honeycomb(n = 15, ncol = 5)[15,]
pos_honeycomb(n = 15, ncol = 5)[1:4,]

r flipbookr::chunk_reveal('pos_spoke_x_11', title = '### pos_spoke_x')

pos_spoke_x()
pos_spoke_x(n = 10)

r flipbookr::chunk_reveal('pos_spoke_y_12', title = '### pos_spoke_y')

pos_spoke_y(n = 6)
ggcanvas() +
stamp_label(label = "hello",
           x = pos_spoke_x(n = 5),
           y = pos_spoke_y(n = 5)) +
stamp_point(x = pos_spoke_x(n = 5, rot = 0),
            y = pos_spoke_y(n = 5, rot = 0))

r flipbookr::chunk_reveal('pos_spoke_13', title = '### pos_spoke')

# Using w plotspace
ggcanvas() +
stamp_label(label = c("hi", "bye", "tchao"),
            xy = pos_spoke(n = 3,
            rotation = -.5,
            radius = .5))

r flipbookr::chunk_reveal('pos_spoke_14', title = '### pos_spoke')

pos_spoke()
pos_spoke(n = 10)

r flipbookr::chunk_reveal('pos_wrap_multi_15', title = '### pos_wrap_multi')

# in plot
ggcanvas() +
  stamp_point(xy =
      pos_wrap_multi(n = c(5, 10),
                     ncol = 4))

r flipbookr::chunk_reveal('pos_wrap_multi_16', title = '### pos_wrap_multi')

# just printing
pos_wrap_multi(n = c(3, 4), ncol = 2)
pos_wrap_multi()

r flipbookr::chunk_reveal('pos_wrap_png_17', title = '### pos_wrap_png')

ggcanvas() +
    stamp_png(x0y0 = pos_wrap_png(n = 7)) +
    stamp_png(x0y0 = pos_wrap_png(n = 5,
              y0 = -2.5), width = .85)

r flipbookr::chunk_reveal('pos_wrap_18', title = '### pos_wrap')

pos_wrap()
pos_wrap(n = 7, ncol = 2)

r flipbookr::chunk_reveal('stamp_arrow_19', title = '### stamp_arrow')

# several arrows
 ggcanvas() +
 stamp_arrow(color = "steelblue") +
 stamp_arrow(x = 1:5, y = 2, xend = 2:6,
 headlength = .04, type = "closed",
 color = "darkred") +
 stamp_arrow(x = .5, xend = 1.5,
 ends = "both", angle = 60)

r flipbookr::chunk_reveal('stamp_arrow_20', title = '### stamp_arrow')

# stamp arrow on plot
library(ggplot2)
ggplot(cars) +
  aes(speed, dist) +
  geom_point() +
  stamp_arrow() +
  stamp_arrow(color = "darkred",
  xend = 15, yend = 75)

r flipbookr::chunk_reveal('stamp_circle_21', title = '### stamp_circle')

# lots of circles
 ggcanvas() +
 stamp_circle(color = "turquoise4", radius = 3, fill = "turquoise") +
 stamp_circle(fill = "slateblue2", radius = 2) +
 stamp_circle(linetype = "dashed", alpha = .5, fill = "plum2") +
 stamp_circle(x0 = 1, y0 = 1.5, rotation = .25, size = 0,
  fill = "goldenrod2") +
 stamp_circle(n = 50, radius = .2, size = 0) +
 stamp_spoke(angle = pi * 1:7/15, radius = 2)

r flipbookr::chunk_reveal('stamp_circle_22', title = '### stamp_circle')

# on a canvas
 ggcanvas() +
  stamp_circle(x0 = c(0, 2.5),
  fill = "magenta", color = "purple") +
  stamp_label(xy = pos_spoke(x0 = 0, n = 3),
              label = c("hi", "hello", "bye")) +
  stamp_point(color = "turquoise")

r flipbookr::chunk_reveal('stamp_circle_23', title = '### stamp_circle')

# on plot space
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 geom_point() +
 stamp_circle(color = "darkred", radius = 12)

r flipbookr::chunk_reveal('stamp_circle_24', title = '### stamp_circle')

# some more
 ggcanvas() +
  stamp_circle(x0y0 = pos_wrap(n = 5, ncol = 3, height = 1.5),
               radius = .55)

r flipbookr::chunk_reveal('stamp_curve_25', title = '### stamp_curve')

# a curve
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 geom_point() +
 stamp_curve(color = "darkred",
 xend = 15, yend = 75)

r flipbookr::chunk_reveal('stamp_curve_26', title = '### stamp_curve')

# more curves
ggcanvas() +
 stamp_curve() +
 stamp_curve(color = "green") +
 stamp_curve(x = 1:5, yend = 2, xend = 2:6,
 size = 8, alpha = .5) +
 stamp_point(x = 1:5, y = 0)

r flipbookr::chunk_reveal('stamp_ellipse_27', title = '### stamp_ellipse')

# an ellipse
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 stamp_ellipse() +
 stamp_ellipse(color = "plum4", x0 = 2, y0 = 3, angle = pi/6)

r flipbookr::chunk_reveal('stamp_ellipse_28', title = '### stamp_ellipse')

# several
ggcanvas() +
 stamp_ellipse(color = "green") +
 stamp_ellipse(x0 = 1:5, y0 = 2, size = 2)

r flipbookr::chunk_reveal('stamp_heart_29', title = '### stamp_heart')

# lots of polygons
 ggcanvas() +
 stamp_heart(color = "turquoise4", radius = 3, fill = "turquoise") +
 stamp_heart(fill = "slateblue2") +
 stamp_heart(linetype = "dashed", alpha = .5, fill = "plum2") +
 stamp_heart(x0 = 1, y0 = 1.5, n = 3, rotation = .25, size = 0,
  fill = "goldenrod2") +
 stamp_heart(n = 50, radius = .2, size = 0) +
 stamp_spoke(angle = pi * 1:7/15, radius = 2)

r flipbookr::chunk_reveal('stamp_heart_30', title = '### stamp_heart')

# on a canvas
 ggcanvas() +
  stamp_heart(n = 18, x0 = c(0, 2.5),
  fill = "magenta", color = "purple") +
  stamp_label(x = pos_spoke_x(x0 = 0, n = 3),
              y = pos_spoke_y(y0 = 0, n = 3),
              label = c("hi", "hello", "bye")) +
  stamp_point(color = "turquoise")

r flipbookr::chunk_reveal('stamp_heart_31', title = '### stamp_heart')

# on plot space
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 geom_point() +
 stamp_heart(color = "darkred",
             fill = "pink")
 ggcanvas() +
  stamp_heart()

r flipbookr::chunk_reveal('stamp_heart_32', title = '### stamp_heart')

# some more
 ggcanvas() +
  stamp_heart(x0y0 = pos_wrap(n = 5, ncol = 3, height = 1.5),
                radius = .5) +
  stamp_text(xy = pos_wrap(n = 5, ncol = 3,
           height = 1.5), label = LETTERS[1:5])

r flipbookr::chunk_reveal('stamp_hline_33', title = '### stamp_hline')

# on a canvas
ggcanvas() +
stamp_hline() +
stamp_hline(1:6,
           linetype = rep(c("dotted", "dashed"), 3))

r flipbookr::chunk_reveal('stamp_hline_34', title = '### stamp_hline')

library(ggplot2)
ggplot(cars) +
aes(speed, dist) +
stamp_hline()

r flipbookr::chunk_reveal('stamp_label_35', title = '### stamp_label')

# label on a canvas
ggcanvas() +
   stamp_label()

r flipbookr::chunk_reveal('stamp_label_36', title = '### stamp_label')

# labels on a plot
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 geom_point() +
 stamp_label(x = 20, y = 10) +
 stamp_label(label = "hi",
 y = c(100, 75, 50), x = 5, fill = "cadetblue2", label.size = 0)

r flipbookr::chunk_reveal('stamp_png_37', title = '### stamp_png')

# png spokes
ggcanvas() +
  stamp_png()

r flipbookr::chunk_reveal('stamp_png_38', title = '### stamp_png')

# stamp in plotspace
library(ggplot2)
ggplot(cars, aes(dist, speed)) +
  geom_point() +
  stamp_png(x0 = 5:11*10, y0 = 10,
            height = 1, width = 10) +
  scale_fill_identity()

r flipbookr::chunk_reveal('stamp_png_39', title = '### stamp_png')

# tiling pngs needs work
ggcanvas() +
  stamp_png(x0y0 = pos_wrap_png(),
  alpha = .75)

r flipbookr::chunk_reveal('stamp_png_40', title = '### stamp_png')

# two stamps
ggcanvas() +
  stamp_png() +
  stamp_png(x0 = 2:3, y0 = 6,
            width = .95) +
  scale_fill_identity()

r flipbookr::chunk_reveal('stamp_point_41', title = '### stamp_point')

# more points on canvas
ggcanvas() +
 stamp_point(color = "darkgreen") +
 stamp_point(x = 1:5, y = 2,
             size = 8, alpha = .5) +
 stamp_point(xy = pos_wrap(y0 = -2,
             n = 13, ncol = 4),
             color = "plum") +
 stamp_point(xy = pos_wrap(x0 = 1,
             n = 7, ncol = 4, width = .5))

r flipbookr::chunk_reveal('stamp_point_42', title = '### stamp_point')

# stamp in plot space
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 geom_point() +
 stamp_point() +
 stamp_point(color = "red", x = 10, y = 100)

r flipbookr::chunk_reveal('stamp_polygon_holes_43', title = '### stamp_polygon_holes')

# some more
 ggcanvas() +
  stamp_png(width = 3) +
  stamp_polygon_holes(x0y0 = pos_honeycomb(n = 5),
  radius = .95,
                        radius_outer = Inf) +
  stamp_polygon(alpha = .2, radius = .95,
                color = "grey30")

r flipbookr::chunk_reveal('stamp_polygon_inverse_44', title = '### stamp_polygon_inverse')

# lots of polygons
 ggcanvas() +
 stamp_polygon_inverse(radius = 3, n = 5,
                       fill = "turquoise") +
 stamp_polygon_inverse(fill = "slateblue2",
                       radius = 1.5, n = 7) +
 stamp_polygon_inverse(linetype = "dashed",
                       alpha = .5, fill = "plum2") +
 stamp_polygon_inverse(x0 = 1, y0 = 1.5, n = 3,
                       rotation = .25, size = 0,
                       fill = "goldenrod2") +
 stamp_polygon_inverse(n = 50, radius = .2,
                       size = 0) +
 stamp_spoke(angle = pi * 1:7/15, radius = 2)

r flipbookr::chunk_reveal('stamp_polygon_inverse_45', title = '### stamp_polygon_inverse')

# on a canvas
 ggcanvas() +
  stamp_polygon_inverse(n = 3, x0 = c(0,2.5),
  fill = "magenta", color = "purple") +
  stamp_label(x = pos_spoke_x(x0 = 0, n = 3),
              y = pos_spoke_y(y0 = 0, n = 3),
              label = c("hi", "hello", "bye")) +
  stamp_point(color = "turquoise")

r flipbookr::chunk_reveal('stamp_polygon_inverse_46', title = '### stamp_polygon_inverse')

# on plot space
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 geom_point() +
 stamp_polygon_inverse(x0 = 20, y0 =50, color = "darkred",
 size = .5,
 radius = 10)

r flipbookr::chunk_reveal('stamp_polygon_inverse_47', title = '### stamp_polygon_inverse')

# some more
 ggcanvas() +
  stamp_png() +
  stamp_polygon_inverse(radius = .45,
                        radius_outer = Inf) +
  stamp_polygon(alpha = .2, radius = .45,
                color = "grey30")

r flipbookr::chunk_reveal('stamp_polygon_48', title = '### stamp_polygon')

# lots of polygons
 ggcanvas() +
 stamp_polygon(color = "turquoise4", radius = 3, n = 5, fill = "turquoise") +
 stamp_polygon(fill = "slateblue2", radius = 2, n = 7) +
 stamp_polygon(linetype = "dashed", alpha = .5, fill = "plum2") +
 stamp_polygon(x0 = 1, y0 = 1.5, n = 3, rotation = .25, size = 0,
  fill = "goldenrod2") +
 stamp_polygon(n = 50, radius = .2, size = 0) +
 stamp_spoke(angle = pi * 1:7/15, radius = 2)

r flipbookr::chunk_reveal('stamp_polygon_49', title = '### stamp_polygon')

# on a canvas
 ggcanvas() +
  stamp_polygon(n = 3, x0 = c(0, 2.5),
  fill = "magenta", color = "purple") +
  stamp_label(x = pos_spoke_x(x0 = 0, n = 3),
              y = pos_spoke_y(y0 = 0, n = 3),
              label = c("hi", "hello", "bye")) +
  stamp_point(color = "turquoise")

r flipbookr::chunk_reveal('stamp_polygon_50', title = '### stamp_polygon')

# on plot space
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 geom_point() +
 stamp_polygon(color = "darkred", radius = 5)

r flipbookr::chunk_reveal('stamp_polygon_51', title = '### stamp_polygon')

# some more
 ggcanvas() +
  stamp_polygon(x0y0 = pos_wrap(n = 5, ncol = 3, height = 1.5),
                radius = .55, n = 7) +
  stamp_text(xy = pos_wrap(n = 5, ncol = 3,
           height = 1.5), label = LETTERS[1:5])

r flipbookr::chunk_reveal('stamp_rect_52', title = '### stamp_rect')

# on a canvas
ggcanvas() +
 stamp_rect(fill = "green") +
 stamp_rect(alpha = .8,
            fill = "steelblue",
            size = 0,
            xmin = 2, xmax = 3,
            ymin = 5, ymax = 8) +
 coord_equal()

r flipbookr::chunk_reveal('stamp_rect_53', title = '### stamp_rect')

# rect
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 geom_point() +
 stamp_rect(color = "red") +
 stamp_rect(
            xxyy = data.frame(xmin = 1:4*3, xmax = 2:5*3,
            ymin = 1:4*6, ymax = 1:8*6))

r flipbookr::chunk_reveal('stamp_segment_54', title = '### stamp_segment')

# segment on plot space
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 geom_point() +
 stamp_segment(color = "darkred",
 xend = 15, yend = 75)

r flipbookr::chunk_reveal('stamp_segment_55', title = '### stamp_segment')

# segments on canvas
 ggcanvas() +
 stamp_segment(color = "green") +
 stamp_segment(x = 1:5, y = 2, xend = 2:6,
 size = 8, alpha = .5, lineend = "round")

r flipbookr::chunk_reveal('stamp_spoke_56', title = '### stamp_spoke')

# on canvas
 ggcanvas() +
 stamp_spoke(color = "green") +
 stamp_spoke(x = 2, y = 2, angle = pi * 1:8/4) +
 stamp_circle(x0 = 2, y0 = 2, radius = 1) +
 stamp_spoke(x = 1.5, y = 0,
            angle = pi * 1:50/50,
            alpha = 1:50/50) +
 stamp_text(x = 2, y = 2, label = "Hi!") +
 coord_equal() +
 theme_void()

r flipbookr::chunk_reveal('stamp_spoke_57', title = '### stamp_spoke')

# on plot
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 geom_point() +
 stamp_spoke(color = "darkred", radius = 25)

r flipbookr::chunk_reveal('stamp_text_box_58', title = '### stamp_text_box')

# label on a canvas
ggcanvas() +
   stamp_label()

r flipbookr::chunk_reveal('stamp_text_box_59', title = '### stamp_text_box')

# labels on a plot
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 geom_point() +
 stamp_label(x = 20, y = 10) +
 stamp_label(label = "hi",
 y = c(100, 75, 50), x = 5, fill = "cadetblue2", label.size = 0)

r flipbookr::chunk_reveal('stamp_text_60', title = '### stamp_text')

# some more
 ggcanvas() +
  stamp_text() +
  stamp_text(label = letters[1:4],
  xy = pos_spoke(n = 4)) +
  stamp_text(x = 2) +
  scale_x_continuous(limits = c(-1,3)) +
  stamp_text(y = 1:2, x = 2,
             label = "Hellonthere!") +
  theme_void() +
  stamp_point(x = 1, y = 1,
              alpha = .4) +
  theme(plot.background =
       element_rect(fill = "seagreen",
       size = 0)) +
  scale_y_continuous(limits = c(-1,3))

r flipbookr::chunk_reveal('stamp_text_61', title = '### stamp_text')

# stamping text on a plot
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 geom_point() +
 stamp_text(label = "A 1920s study on speed v. stopping distance tells us there is a correlation between how fast a car is going and how long it takes to stop.",
            x = 3, y = 110,
            size = 5,
            text_wrap = TRUE,
            hjust = 0) +
 stamp_text(label = "The Pearsonncorrelationnis about 0.81",
           x = 18, y = 15,
           size = 5, hjust = 0) +
 stamp_text(label = 'bold(italic(p)*"-value"<"0.01")',
            parse = TRUE,
            size = 5, x = 23, y = 2)
 cor.test(cars$speed, cars$dist)

r flipbookr::chunk_reveal('stamp_textbox_62', title = '### stamp_textbox')

# label on a canvas
library(ggtext)
ggdraft() +
   stamp_textbox(40, 30, width = unit(0.3, "npc")) +
   stamp_point(x = 1:3*10, y = 1)

r flipbookr::chunk_reveal('stamp_textbox_63', title = '### stamp_textbox')

# labels on a plot
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 geom_point() +
 stamp_textbox(x = 20, y = 40) +
 stamp_textbox(x = 20, y = 20, label = "*hello*") +
 stamp_textbox(label = "**world**", hjust = 0,
 y = 10, x = 5, fill = "cadetblue2", label.size = 0) +
 stamp_point()

r flipbookr::chunk_reveal('stamp_tile_64', title = '### stamp_tile')

# on a canvas
ggcanvas() +
 stamp_tile(fill = "green") +
 stamp_tile(x = 1:5, y = 2, alpha = .8,
            fill = "steelblue",
            width = .95,
            size = 0) +
 coord_equal()

r flipbookr::chunk_reveal('stamp_tile_65', title = '### stamp_tile')

# tile
library(ggplot2)
ggplot(cars) +
 aes(speed, dist) +
 geom_point() +
 stamp_tile(color = "red", x = 10,
            y = 90:100) +
 stamp_tile(height = 10,
            xy = pos_spoke(x0 = 20, n = 15,
            radius = 6))

r flipbookr::chunk_reveal('stamp_tile_66', title = '### stamp_tile')

# using a positioner
ggcanvas() +
 stamp_tile(xy = pos_spoke())

r flipbookr::chunk_reveal('stamp_vline_67', title = '### stamp_vline')

# on a canvas
ggcanvas() +
stamp_vline(color = "cadetblue") +
stamp_vline(0:5,
           linetype = rep(c("dotted", "dashed"), 3))

r flipbookr::chunk_reveal('stamp_vline_68', title = '### stamp_vline')

library(ggplot2)
ggplot(cars) +
aes(speed, dist) +
geom_point() +
stamp_vline()


EvaMaeRey/ggstamp documentation built on June 30, 2022, 11 p.m.