Skip to content

Commit

Permalink
20: Add a hex sticker (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielinteractive authored Feb 12, 2024
1 parent b990b8c commit 85e78e2
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 19 deletions.
15 changes: 10 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# R specific hooks: https://github.com/lorenzwalthert/precommit
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.3.2.9013
rev: v0.4.0
hooks:
- id: style-files
args: [--style_pkg=styler, --style_fun=tidyverse_style]
Expand All @@ -13,6 +13,7 @@ repos:
- knitr
- testthat
- Rdpack
- etm
- openpharma/roxytypes
- openpharma/roxylint
- id: use-tidy-description
Expand Down Expand Up @@ -48,15 +49,19 @@ repos:
- id: parsable-R
- id: no-browser-statement
- id: deps-in-desc
exclude: >
(?x)^(
data-raw/.*
)$
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0
rev: v4.0.0-alpha.8
hooks:
- id: prettier
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
args: ["--maxkb=200"]
args: ["--maxkb=1000"]
- id: end-of-file-fixer
exclude: '\.Rd'
- id: trailing-whitespace
Expand All @@ -79,6 +84,6 @@ repos:
files: '\.Rhistory|\.RData|\.Rds|\.rds$'
# `exclude: <regex>` to allow committing specific files.
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.35.0
rev: v0.39.0
hooks:
- id: markdownlint
91 changes: 91 additions & 0 deletions data-raw/create_hex_sticker.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
library(hexSticker)
library(magick)
library(rsvg)
library(svglite)

less_than_black <- "gray27"
very_light_gray <- "gray98"
out_path <- file.path(getwd(), "man/figures/logo-large")
out_file <- paste(out_path, "png", sep = ".")

savvyr_plot <- function() {
cuminc_exp <- function(t, lambda) {
# cumulative incidence functions for exponential distribution
# t: time
# lambda: vector of rates
s <- sum(lambda)
res <- matrix(NA, ncol = length(lambda), nrow = length(t))
res[, seq_along(lambda)] <- (1 - exp(-s * t)) / s
res[t <= 0, seq_along(lambda)] <- 0
res <- t(lambda * t(res))
rownames(res) <- t
colnames(res) <- lambda
return(res)
}

ts <- seq(-5, 25, by = 0.01)
l1 <- c(1, 1.6) / 10
l2 <- c(1.8, 1.2) / 10


# cumulative incidence
plot(0, 0,
xlim = c(0, 20), ylim = c(0, 1),
type = "n", xlab = "time", ylab = "cumulative AE risk",
main = "cumulative AE risk",
xaxt = "n", yaxt = "n", col.main = less_than_black, col.lab = less_than_black,
axes = FALSE, mgp = c(1, 1, 0), bg = very_light_gray
)
lines(ts, cuminc_exp(ts, l1)[, 1], col = "blue", lwd = 3)
lines(ts, cuminc_exp(ts, l2)[, 1], col = "green", lwd = 3)
axis(side = 2, at = c(0, 1), las = 1, col = less_than_black, col.axis = less_than_black)
axis(side = 1, at = c(0, 20), labels = c(0, NA), las = 1, col = less_than_black, col.axis = less_than_black)
text(x = 20, y = 0.53, labels = "control", col = "green", adj = c(1, 0.5), cex = 1)
text(x = 20, y = 0.33, labels = "experimental", col = "blue", adj = c(1, 0.5), cex = 1)
}

savvyr_plot()

tmp <- tempdir()
savvyr_fig <- file.path(tmp, "savvyr_plot.png")
png(filename = savvyr_fig, res = 100, width = 400, height = 400, bg = "transparent")
savvyr_plot()
dev.off()

plot(magick::image_read(savvyr_fig))

x <- sticker(
subplot = savvyr_fig,
s_x = 0.9,
s_y = 0.95,
s_width = 0.8,
s_height = 0.8,
package = "savvyr",
url = "github.com/openpharma/savvyr",
u_size = 24,
u_color = "blue",
p_x = 1.0,
p_y = 1.3,
p_color = "blue",
p_size = 200,
p_family = "mono",
h_fill = very_light_gray,
h_color = less_than_black,
h_size = 2,
spotlight = FALSE,
l_y = 1,
l_x = 1,
l_width = 3,
l_height = 3,
l_alpha = 0.3,
dpi = 2000,
white_around_sticker = TRUE,
filename = out_file
)
# But therefore we now need to postprocess the image by transforming white
# to transparent background.
out_img <- magick::image_read(out_file)
out_img <- magick::image_transparent(out_img, color = "white")
magick::image_write(out_img, path = out_file)

usethis::use_logo(out_file)
Binary file added data-raw/savvyr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 19 additions & 14 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
Aalen
AdVerse
AE
al
Beyersmann
BiocCheck
Bove
CMD
et
Forkers
funder
github
gitleaks
Hoffmann
initializer
Johansen
Kaplan
Kaspar
Kuenzel
L<U+00FC>bbert
Pkgdown
Pre
Roxygen
Sabanes
SuperLinter
github
gitleaks
initializer
pre
repo
Forkers
AE
al
et
Lübbert
Roxygen
Rufibach
Sabanes
savvyr
Schmoor
Stegherr
SuperLinter
Ulm
Universität
Universit
Universit<U+00E4>t
VarYing
Aalen
Johansen
Binary file added man/figures/logo-large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions man/savvyr-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 85e78e2

Please sign in to comment.