pkg <- read.dcf(here::here("DESCRIPTION"), fields = "Package")[1]
description <- read.dcf(here::here("DESCRIPTION"), fields = "Description")[1]
library(hexSticker)
library(dplyr)
library(ggplot2)
library(ggimage)

File path

Create file path.

filename <- here::here("inst/hex/hex.png")
dir.create(dirname(filename), showWarnings = FALSE, recursive = TRUE)

You can make awesome hex stickers for your R packages using hexSticker.

echolocatoR logo

echoR_logo <- here::here("images/echolocatoR_logo2.png")

Bat logo

Download bat logo from the echoverseTemplate GitHub Release.

tmp <- tempfile()
#### Side view ####
URL <- "https://github.com/RajLabMSSM/echoverseTemplate/releases/download/latest/bat_silhouette.png"   
#### Front view ####
# URL <- "https://github.com/RajLabMSSM/echoverseTemplate/releases/download/latest/bat_silhouette_front.png"   
download.file(URL, tmp)

Background

Create background with ggplot2.

set.seed(1234)
n_bats <- 20
d <- data.frame(x = -rexp(n_bats, rate = 3),
                y = rexp(n_bats, rate = 3)
                ) %>%
  dplyr::mutate(image = URL,
                bsize = abs(x*y^2)) %>%
  dplyr::arrange(dplyr::desc(x), dplyr::desc(y))
qplot(d$x, d$y, size=d$bsize)

Import data points for reproducibility.

d <- data.table::fread("https://github.com/RajLabMSSM/echoverseTemplate/releases/download/latest/echoverse_points.csv.gz")
# d$bsize <- d$bsize*d$y
d <- rbind(d,
  data.frame(x= -.9, 
             y=max(d$y)*.9, 
             image= echoR_logo, 
             bsize=2.2)
  )
d$image <- factor(d$image, unique(d$image), ordered = TRUE)
gg_bats <- ggplot(d, aes(x = x, y = y, color=log(bsize,1.0001), image=image)) + 
  geom_image(aes(size=I(bsize)), alpha=1) + # image_fun=magick::image_flop
  scale_color_gradient(low = "#194f68", high = "#56ffff") +   
  coord_cartesian(clip = "off") +
  labs(title = "echoverse") +  
  theme_void() +
  theme(plot.title = element_text(color = "#56ffff", 
                                  margin = margin(b=15),
                                  size = 25,
                                  hjust = .5, vjust = -.9, family = "Aller_Rg"), 
        legend.position = "none") 
# print(gg_bats)

hexSticker

s_size = 1
stick <- hexSticker::sticker(
  subplot = gg_bats, 
  #### Package name ####
  package = pkg, p_size=14, p_y = 1.5,
  #### Subplot #####
  s_x=1, s_y=.84,  s_height = s_size*1.15, s_width = s_size,
  #### Fill & border ####
  h_fill = "#25355c", h_color = "#41c6c8", #56ffff
  #### Spotlight ####
  spotlight = TRUE, l_alpha = .3, l_width = 10,
  #### File output ####
  filename = filename, dpi = 300)
# print(stick)

Session Info

utils::sessionInfo()



RajLabMSSM/echolocatoR documentation built on Jan. 29, 2023, 6:04 a.m.