|
| 1 | +--- |
| 2 | +title: "hexSticker" |
| 3 | +author: "<h4>Author: <i>Brian M. Schilder</i></h4>" |
| 4 | +date: "<h4>Updated: <i>`r format( Sys.Date(), '%b-%d-%Y')`</i></h4>" |
| 5 | +output: |
| 6 | + BiocStyle::html_document |
| 7 | +vignette: > |
| 8 | + %\VignetteIndexEntry{hexSticker} |
| 9 | + %\VignetteEngine{knitr::rmarkdown} |
| 10 | + %\VignetteEncoding{UTF-8} |
| 11 | +--- |
| 12 | + |
| 13 | +```{r, echo=FALSE, include=FALSE} |
| 14 | +pkg <- read.dcf(here::here("DESCRIPTION"), fields = "Package")[1] |
| 15 | +description <- read.dcf(here::here("DESCRIPTION"), fields = "Description")[1] |
| 16 | +``` |
| 17 | + |
| 18 | +You can make awesome hex stickers for your R packages using: |
| 19 | + |
| 20 | +- [hexSticker](https://github.com/GuangchuangYu/hexSticker) |
| 21 | +- [ggimage](https://github.com/GuangchuangYu/ggimage) |
| 22 | +lets you render images as data points. |
| 23 | +- [ggpattern](https://coolbutuseless.github.io/package/ggpattern/) |
| 24 | +lets you fill objects with patterns or images. |
| 25 | +- [magick](https://cran.r-project.org/web/packages/magick/vignettes/intro.html) |
| 26 | +modify PNGs. |
| 27 | + |
| 28 | +# `r pkg` |
| 29 | + |
| 30 | +```{r setup} |
| 31 | +# If you're using R<4.1.1, need this version of rvcheck |
| 32 | +# devtools::install_version('rvcheck',version='0.1.8') |
| 33 | +library(hexSticker) |
| 34 | +library(dplyr) |
| 35 | +library(ggplot2) |
| 36 | +library(ggimage) |
| 37 | +# library(ggpattern)# remotes::install_github("coolbutuseless/ggpattern") |
| 38 | +``` |
| 39 | + |
| 40 | +## File path |
| 41 | + |
| 42 | +Create file path. |
| 43 | + |
| 44 | +```{r} |
| 45 | +filename <- here::here("inst/hex/hex.png") |
| 46 | +dir.create(dirname(filename), showWarnings = FALSE, recursive = TRUE) |
| 47 | +``` |
| 48 | + |
| 49 | +## Bat logo |
| 50 | + |
| 51 | +Download bat logo from the |
| 52 | +[*echoverseTemplate*](https://github.com/RajLabMSSM/echoverseTemplate/releases/tag/latest) |
| 53 | +GitHub Release. |
| 54 | + |
| 55 | +```{r} |
| 56 | +tmp <- tempfile() |
| 57 | +#### Side view #### |
| 58 | +URL <- "https://github.com/RajLabMSSM/echoverseTemplate/releases/download/latest/bat_silhouette.png" |
| 59 | +#### Front view #### |
| 60 | +# URL <- "https://github.com/RajLabMSSM/echoverseTemplate/releases/download/latest/bat_silhouette_front.png" |
| 61 | +download.file(URL, tmp) |
| 62 | +``` |
| 63 | + |
| 64 | +## Background |
| 65 | + |
| 66 | +Create background with `ggplot2`. |
| 67 | + |
| 68 | +```{r, eval=FALSE} |
| 69 | +set.seed(1234) |
| 70 | +n_bats <- 20 |
| 71 | +d <- data.frame(x = -rexp(n_bats, rate = 3), |
| 72 | + y = rexp(n_bats, rate = 3) |
| 73 | + ) |> |
| 74 | + dplyr::mutate(image = URL, |
| 75 | + bsize = abs(x*y^2)) |> |
| 76 | + dplyr::arrange(dplyr::desc(x), dplyr::desc(y)) |
| 77 | +qplot(d$x, d$y, size=d$bsize) |
| 78 | +``` |
| 79 | + |
| 80 | +Import data points for reproducibility. |
| 81 | + |
| 82 | +```{r} |
| 83 | +d <- data.table::fread("https://github.com/RajLabMSSM/echoverseTemplate/releases/download/latest/echoverse_points.csv.gz") |
| 84 | +``` |
| 85 | + |
| 86 | + |
| 87 | +```{r} |
| 88 | +gg_bats <- ggplot(d, aes(x = x, y = y, color=bsize, image=image)) + |
| 89 | + geom_image(aes(size=I(bsize)), alpha=1) + |
| 90 | + scale_color_gradient(low = "#194f68", high = "#56ffff") + |
| 91 | + coord_cartesian(clip = "off") + |
| 92 | + labs(title = "echoverse") + |
| 93 | + theme_void() + |
| 94 | + theme(plot.title = element_text(color = "#56ffff", size = 25, |
| 95 | + hjust = .5, vjust = 5, family = "Aller_Rg"), |
| 96 | + legend.position = "none") |
| 97 | +
|
| 98 | +print(gg_bats) |
| 99 | +``` |
| 100 | + |
| 101 | +## hexSticker |
| 102 | + |
| 103 | +```{r} |
| 104 | +s_size = 1 |
| 105 | +stick <- hexSticker::sticker( |
| 106 | + subplot = gg_bats, |
| 107 | + #### Package name #### |
| 108 | + package = pkg, p_size=14, p_y = 1.4, |
| 109 | + #### Subplot ##### |
| 110 | + s_x=1, s_y=.8, s_height = s_size, s_width = s_size, |
| 111 | + #### Fill & border #### |
| 112 | + h_fill = "#25355c", h_color = "#41c6c8", #56ffff |
| 113 | + #### Spotlight #### |
| 114 | + spotlight = TRUE, l_alpha = .3, l_width = 10, |
| 115 | + #### File output #### |
| 116 | + filename = filename, dpi = 300) |
| 117 | +print(stick) |
| 118 | +``` |
| 119 | + |
| 120 | + |
| 121 | +# Session Info |
| 122 | + |
| 123 | +<details> |
| 124 | + |
| 125 | +```{r Session Info} |
| 126 | +utils::sessionInfo() |
| 127 | +``` |
| 128 | + |
| 129 | +</details> |
0 commit comments