Skip to content

Instantly share code, notes, and snippets.

@matt-dray
Last active February 28, 2025 23:39
Show Gist options
  • Select an option

  • Save matt-dray/df8b96187722dfc9cf76ac5f203cccfc to your computer and use it in GitHub Desktop.

Select an option

Save matt-dray/df8b96187722dfc9cf76ac5f203cccfc to your computer and use it in GitHub Desktop.

Revisions

  1. matt-dray revised this gist Feb 28, 2025. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion aftables-hex.R
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,12 @@
    # hex sticker for {aftables}:
    # https://github.com/best-practice-and-impact/aftables

    # having installed the Free Sans font:
    # https://www.fontspace.com/freesans-font-f13276
    # and installed {gex}:
    remotes::install_github("matt-dray/gex")
    # and {ggplotify}:
    install.packages("ggplotify")

    temp_path <- tempfile(fileext = ".png")
    gex::open_device(temp_path)
    @@ -45,7 +50,13 @@ p <- ggplotify::base2grob(
    frame.plot = FALSE,
    ann = FALSE
    )
    points(nums[[1]], nums[[2]], col = nums[["col"]], pch = 15, cex = 1.8)
    points(
    nums[[1]],
    nums[[2]],
    col = nums[["col"]],
    pch = 15,
    cex = 1.8
    )
    }
    )
    grid::grid.draw(p)
  2. matt-dray created this gist Feb 28, 2025.
    55 changes: 55 additions & 0 deletions aftables-hex.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    # having installed the Free Sans font:
    # https://www.fontspace.com/freesans-font-f13276
    # and installed {gex}:
    remotes::install_github("matt-dray/gex")

    temp_path <- tempfile(fileext = ".png")
    gex::open_device(temp_path)
    gex::add_hex(col = "#042D45")
    gex::add_text(
    "aftables",
    x = 0.5,
    y = 0.7,
    family = "FreeSans",
    size = 23,
    col = "white"
    )
    grid::pushViewport(grid::viewport(x = 0.5, y = 0.2, width = 1, height = 0.75))
    p <- ggplotify::base2grob(
    \() {
    set.seed(2025)
    cols <- c(
    "#12436D",
    "#28A197",
    "#801650",
    "#F46A25",
    "#3D3D3D",
    "#A285D1",
    "#2073BC",
    "#6BACE6",
    "#BFBFBF"
    )
    c_num <- 10
    r_num <- 11
    nums <- expand.grid(1:r_num, 1:c_num)
    nums[["col"]] <- sample(cols, r_num * c_num, replace = TRUE)
    par(mar = rep(0, 4))
    plot(
    nums[[1]],
    nums[[2]],
    pch = "",
    xaxt = "n",
    yaxt = "n",
    bty = "n",
    axes = FALSE,
    frame.plot = FALSE,
    ann = FALSE
    )
    points(nums[[1]], nums[[2]], col = nums[["col"]], pch = 15, cex = 1.8)
    }
    )
    grid::grid.draw(p)
    grid::popViewport()
    gex::add_border(width = 0.04, col = "#2E2E2E")
    gex::close_device()
    system(paste("open", temp_path))