diff --git a/.Rbuildignore b/.Rbuildignore index f599bbe..731edee 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -15,3 +15,4 @@ ^LICENSE\.md$ ^CODE_OF_CONDUCT\.md$ ^README\.Rmd$ +^logo$ diff --git a/README.Rmd b/README.Rmd index 02b9fa3..258e6f0 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,7 +17,7 @@ knitr::opts_chunk$set( ) ``` -# dampack +# dampack dampack website [![CRAN status](https://www.r-pkg.org/badges/version/dampack)](https://CRAN.R-project.org/package=dampack) diff --git a/README.md b/README.md index af7f2d3..2e23250 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# dampack +# dampack dampack website diff --git a/logo/README.md b/logo/README.md new file mode 100644 index 0000000..7db9452 --- /dev/null +++ b/logo/README.md @@ -0,0 +1,42 @@ +# The dampack logo + +The hex sticker is drawn from dampack's own output on `cancer_psa_data`, the package's main +example dataset: + +- **Top panel:** the cost-effectiveness acceptability curves (CEACs) of the three strategies, + from `ceac()`, with the acceptability frontier (CEAF) as the heavy line and squares. +- **Bottom panel:** their expected loss curves (ELCs), from `calc_exp_loss()`, on a log scale. + The heavy line is the frontier, which equals the expected value of perfect information. +- **Dotted line:** both frontiers switch from Radio to Chemo at the same willingness-to-pay + threshold, $40,000/QALY. That is the argument for reporting ELCs alongside the CEAC and + CEAF ([Alarid-Escudero et al., 2019](https://doi.org/10.1016/j.jval.2019.02.008)). + +The colours are viridis option D, the palette of `col = "access"` in dampack's plots. The +wordmark is set in JetBrains Mono Bold (SIL Open Font License). + +## Files + +| File | Use | +|---|---| +| `dampack-hex.svg` | The sticker. | +| `dampack-hex-600dpi.png` | Print: 2 in tall at 600 dpi, transparent outside the hex. | +| `dampack-hex-small.svg` | ELCs only, for small sizes where two panels are too busy. | +| `dampack-hex-icon.svg` | ELCs only, without text, for favicons. | +| `../man/figures/logo.png` | README and the pkgdown home page (240 × 278 px). | +| `../pkgdown/favicon/` | Site favicons, rendered from the icon. | + +The SVGs load the wordmark font from Google Fonts. Print shops that ask for outlined text +need the text in `dampack-hex.svg` converted to paths, for example with +Inkscape (*Path > Object to Path*). + +## Rebuilding + +From the package root: + +```sh +Rscript logo/make_hex.R # SVGs, from the current dampack +bash logo/render.sh # PNGs and favicons, with headless Google Chrome +``` + +`logo/` and `pkgdown/` are excluded from the package build, so only `man/figures/logo.png` +(17 KB) is installed with dampack. diff --git a/logo/dampack-hex-600dpi.png b/logo/dampack-hex-600dpi.png new file mode 100644 index 0000000..fbb9b12 Binary files /dev/null and b/logo/dampack-hex-600dpi.png differ diff --git a/logo/dampack-hex-icon.svg b/logo/dampack-hex-icon.svg new file mode 100644 index 0000000..e11e782 --- /dev/null +++ b/logo/dampack-hex-icon.svg @@ -0,0 +1,12 @@ + +dampack + + + + + + + + + + diff --git a/logo/dampack-hex-small.svg b/logo/dampack-hex-small.svg new file mode 100644 index 0000000..0686aaf --- /dev/null +++ b/logo/dampack-hex-small.svg @@ -0,0 +1,25 @@ + +dampack + + + + + + + + + + + + + + + + + + +WTP → +dampack + + + diff --git a/logo/dampack-hex.svg b/logo/dampack-hex.svg new file mode 100644 index 0000000..d4334ca --- /dev/null +++ b/logo/dampack-hex.svg @@ -0,0 +1,39 @@ + +dampack + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +WTP → +dampack + + + diff --git a/logo/make_hex.R b/logo/make_hex.R new file mode 100644 index 0000000..6bd560c --- /dev/null +++ b/logo/make_hex.R @@ -0,0 +1,130 @@ +# Builds the dampack hex sticker from the package's own output. +# +# The sticker shows the cost-effectiveness acceptability curves (CEACs) with the +# acceptability frontier (CEAF) above the expected loss curves (ELCs) of the three +# strategies in `cancer_psa_data`, on one willingness-to-pay (WTP) axis. Both frontiers +# switch from Radio to Chemo at the same threshold, marked by the dotted line +# (Alarid-Escudero et al. 2019, Value in Health 22(5):611-618, doi:10.1016/j.jval.2019.02.008). +# +# Run from the package root: Rscript logo/make_hex.R +# It writes three SVGs to logo/: +# dampack-hex.svg the sticker (CEAC/CEAF and ELCs) +# dampack-hex-small.svg ELCs only, for small sizes such as a navbar +# dampack-hex-icon.svg ELCs only and no wordmark, for favicons +# logo/README.md explains how the PNGs in man/figures/ and pkgdown/favicon/ are made from them. + +library(dampack) + +# ---- data ------------------------------------------------------------------------------- +data("cancer_psa_data") +l_psa <- make_psa_obj(cost = cancer_psa_data$cost, + effectiveness = cancer_psa_data$effectiveness, + parameters = cancer_psa_data$parameters, + strategies = cancer_psa_data$strategies) +v_wtp <- seq(0, 100000, by = 2500) +df_ceac <- as.data.frame(ceac(l_psa, wtp = v_wtp)) +df_elc <- as.data.frame(calc_exp_loss(l_psa, wtp = v_wtp)) + +# ---- colours and geometry --------------------------------------------------------------- +# viridis option D, the palette of col = "access" in dampack's plots +l_col <- list(bg = "#eff5f2", ink = "#440154", rim = "#31688e", + strat = c("#3b528b", "#21908c", "#5dc863"), mark = "#5dc863") +v_dash <- c("none", "3 2", "1 2") # one line type per strategy, as in col = "bw" +hex_points <- "86.6,0 173.2,50 173.2,150 86.6,200 0,150 0,50" # pointy-top hex, 173.2 x 200 +v_log_loss <- range(log10(df_elc$Expected_Loss)) + +f1 <- function(x) formatC(x, format = "f", digits = 1) +wtp_x <- function(w, x0 = 34, x1 = 139) x0 + w / max(v_wtp) * (x1 - x0) +y_prob <- function(p, top, bottom) bottom - p * (bottom - top) +y_loss <- function(v, top, bottom) { + bottom - (log10(v) - v_log_loss[1]) / diff(v_log_loss) * (bottom - top) +} + +path_d <- function(x, y) paste0("M", paste(f1(x), f1(y), collapse = " L")) + +# strategy curves, frontier line, and frontier squares every 12,500 for one panel +panel <- function(df, value, yfun, lwd_front, sq, x0 = 34, x1 = 139, lwd_strat = 1.2) { + v_strat <- sort(unique(df$Strategy)) + v_curves <- vapply(seq_along(v_strat), function(i) { + d <- df[df$Strategy == v_strat[i], ] + d <- d[order(d$WTP), ] + dash <- if (v_dash[i] == "none") "" else sprintf(' stroke-dasharray="%s"', v_dash[i]) + sprintf('', + path_d(wtp_x(d$WTP, x0, x1), yfun(d[[value]])), l_col$strat[i], lwd_strat, dash) + }, character(1)) + d_f <- df[df$On_Frontier, ] + d_f <- d_f[order(d_f$WTP), ] + front <- sprintf('', + path_d(wtp_x(d_f$WTP, x0, x1), yfun(d_f[[value]])), l_col$ink, lwd_front) + d_sq <- d_f[d_f$WTP %% 12500 == 0, ] + squares <- sprintf('', + f1(wtp_x(d_sq$WTP, x0, x1) - sq / 2), f1(yfun(d_sq[[value]]) - sq / 2), sq, sq, + l_col$mark, l_col$ink) + c(v_curves, front, squares) +} + +grid <- function(v_y) { + sprintf('', + paste(sprintf("M34,%s H139", v_y), collapse = " "), l_col$ink) +} + +wordmark <- function(y) { + sprintf('dampack', + y, l_col$ink) +} +label <- function(x, y, txt, anchor = "end") { + sprintf('%s', + x, y, anchor, l_col$ink, txt) +} + +hex_svg <- function(body, font = TRUE) { + c('', + 'dampack', + if (font) "", + sprintf('', hex_points), + '', + sprintf('', hex_points, l_col$bg), + body, + sprintf('', hex_points, l_col$rim), + "", "") +} + +# ---- the sticker: CEAC/CEAF on top, ELCs below ------------------------------------------ +top <- c(41, 75) # CEAC panel, probability 1 at the top +bot <- c(88, 122) # ELC panel, log expected loss +d_front <- df_ceac[df_ceac$On_Frontier, ] +d_front <- d_front[order(d_front$WTP), ] +wtp_switch <- d_front$WTP[which(d_front$Strategy != d_front$Strategy[1])[1]] +d_front_elc <- df_elc[df_elc$On_Frontier, ] +d_front_elc <- d_front_elc[order(d_front_elc$WTP), ] +stopifnot(wtp_switch == d_front_elc$WTP[which(d_front_elc$Strategy != d_front_elc$Strategy[1])[1]]) + +v_sticker <- hex_svg(c( + grid(c(top, bot)), + sprintf('', + f1(wtp_x(wtp_switch)), top[1] - 3, bot[2] + 3, l_col$ink), + panel(df_ceac, "Proportion", function(p) y_prob(p, top[1], top[2]), 3.2, 4.5), + panel(df_elc, "Expected_Loss", function(v) y_loss(v, bot[1], bot[2]), 3.2, 4.5), + label(139, 131, "WTP →"), + wordmark(156) +)) + +# ---- small version: ELCs only ----------------------------------------------------------- +v_small <- hex_svg(c( + grid(c(46, 83, 120)), + panel(df_elc, "Expected_Loss", function(v) y_loss(v, 46, 120), 3.6, 5.5), + label(139, 129, "WTP →"), + wordmark(153) +)) + +# ---- icon: ELCs only, no wordmark, no text (so it needs no font) ------------------------ +# the icon keeps only the strategy curves and the frontier, drawn wider and thicker +v_icon <- hex_svg(panel(df_elc, "Expected_Loss", function(v) y_loss(v, 48, 146), 12, 0, + x0 = 24, x1 = 149, lwd_strat = 6), font = FALSE) +v_icon <- v_icon[!grepl("^ +render() { + python3 -I - "$1" "$2" "$3" "$5" "$TMP/page.html" <<'EOF' +import sys +svg, w, h, bg, out = sys.argv[1:6] +s = open(svg).read().replace('width="173.2" height="200"', + f'width="{w}" height="{h}" preserveAspectRatio="xMidYMid meet"') +open(out, "w").write("" + s + "") +EOF + "$CHROME" --headless=new --disable-gpu --hide-scrollbars --force-device-scale-factor=1 \ + --default-background-color=00000000 --virtual-time-budget=8000 \ + --window-size="$2,$3" --screenshot="$4" "file://$TMP/page.html" > /dev/null 2>&1 +} + +# the sticker: README, pkgdown home page, and print (600 dpi at 2 in tall) +render logo/dampack-hex.svg 240 278 man/figures/logo.png transparent +render logo/dampack-hex.svg 1039 1200 logo/dampack-hex-600dpi.png transparent + +# favicons for the pkgdown site, from the icon (no text, so no font needed) +cp logo/dampack-hex-icon.svg pkgdown/favicon/favicon.svg +render logo/dampack-hex-icon.svg 96 96 pkgdown/favicon/favicon-96x96.png transparent +render logo/dampack-hex-icon.svg 192 192 pkgdown/favicon/web-app-manifest-192x192.png transparent +render logo/dampack-hex-icon.svg 512 512 pkgdown/favicon/web-app-manifest-512x512.png transparent +render logo/dampack-hex-icon.svg 180 180 pkgdown/favicon/apple-touch-icon.png "#ffffff" +for s in 16 32 48; do render logo/dampack-hex-icon.svg $s $s "$TMP/icon-$s.png" transparent; done + +# favicon.ico holding the 16, 32 and 48 px PNGs +python3 -I - "$TMP" pkgdown/favicon/favicon.ico <<'EOF' +import struct, sys +tmp, out = sys.argv[1], sys.argv[2] +v_png = [open(f"{tmp}/icon-{s}.png", "rb").read() for s in (16, 32, 48)] +header = struct.pack(" pkgdown/favicon/site.webmanifest <<'EOF' +{ + "name": "dampack", + "short_name": "dampack", + "icons": [ + {"src": "/web-app-manifest-192x192.png", "sizes": "192x192", "type": "image/png", "purpose": "maskable"}, + {"src": "/web-app-manifest-512x512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable"} + ], + "theme_color": "#ffffff", + "background_color": "#ffffff", + "display": "standalone" +} +EOF +echo "Rendered man/figures/logo.png, logo/dampack-hex-600dpi.png and pkgdown/favicon/" diff --git a/man/figures/logo.png b/man/figures/logo.png new file mode 100644 index 0000000..cd79329 Binary files /dev/null and b/man/figures/logo.png differ diff --git a/pkgdown/favicon/apple-touch-icon.png b/pkgdown/favicon/apple-touch-icon.png new file mode 100644 index 0000000..d2a2f61 Binary files /dev/null and b/pkgdown/favicon/apple-touch-icon.png differ diff --git a/pkgdown/favicon/favicon-96x96.png b/pkgdown/favicon/favicon-96x96.png new file mode 100644 index 0000000..a3134ca Binary files /dev/null and b/pkgdown/favicon/favicon-96x96.png differ diff --git a/pkgdown/favicon/favicon.ico b/pkgdown/favicon/favicon.ico new file mode 100644 index 0000000..4fcc881 Binary files /dev/null and b/pkgdown/favicon/favicon.ico differ diff --git a/pkgdown/favicon/favicon.svg b/pkgdown/favicon/favicon.svg new file mode 100644 index 0000000..e11e782 --- /dev/null +++ b/pkgdown/favicon/favicon.svg @@ -0,0 +1,12 @@ + +dampack + + + + + + + + + + diff --git a/pkgdown/favicon/site.webmanifest b/pkgdown/favicon/site.webmanifest new file mode 100644 index 0000000..105ff31 --- /dev/null +++ b/pkgdown/favicon/site.webmanifest @@ -0,0 +1,11 @@ +{ + "name": "dampack", + "short_name": "dampack", + "icons": [ + {"src": "/web-app-manifest-192x192.png", "sizes": "192x192", "type": "image/png", "purpose": "maskable"}, + {"src": "/web-app-manifest-512x512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable"} + ], + "theme_color": "#ffffff", + "background_color": "#ffffff", + "display": "standalone" +} diff --git a/pkgdown/favicon/web-app-manifest-192x192.png b/pkgdown/favicon/web-app-manifest-192x192.png new file mode 100644 index 0000000..f320e0c Binary files /dev/null and b/pkgdown/favicon/web-app-manifest-192x192.png differ diff --git a/pkgdown/favicon/web-app-manifest-512x512.png b/pkgdown/favicon/web-app-manifest-512x512.png new file mode 100644 index 0000000..3558c61 Binary files /dev/null and b/pkgdown/favicon/web-app-manifest-512x512.png differ