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

# If you're using R<4.1.1, need this version of rvcheck
# devtools::install_version('rvcheck',version='0.1.8') 
library(hexSticker)
library(dplyr)
library(ggplot2)
library(ggimage)
# library(ggpattern)# remotes::install_github("coolbutuseless/ggpattern")

You can make awesome hex stickers for your R packages using:

r pkg

File path

Create file path to save hex sticker to.

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

Subplot

phenos <- HPOExplorer::make_phenos_dataframe(ancestor = "Neurodevelopmental delay")
phenoNet <- HPOExplorer::make_network_object(phenos = phenos,
                                colour_var = "ontLvl_geneCount_ratio")
# plt <- HPOExplorer::make_network_plot(phenoNet = phenoNet,
#                       colour_var = "ontLvl_geneCount_ratio",
#                       colour_label = "ontLvl_genes", 
#                       interactive = FALSE)
# plt$layers[[2]] <- NULL
phenoNet$pair_id <- seq(nrow(phenoNet))

fig <- plotly::plot_ly(phenoNet, x = ~x, 
                       y = ~y, z = ~ontLvl, 
                       color = ~ontLvl_geneCount_ratio, 
                       type = "scatter3d", mode = "markers") |>
   plotly::add_trace(x = phenoNet$xend, 
                     y = phenoNet$yend, 
                     z = phenoNet$ontLvl, 
            line = as.list(phenoNet$ontLvl_geneCount_ratio),
            type = "scatter3d", mode = "lines", showlegend = FALSE, inherit = FALSE)

# plt2 <- rayshader::plot_gg(ggobj = plt)

ggimage

#### Create function to adjust image opacity ####
alph <- function(img,a=.8) {
  magick::image_fx(img, 
                   expression = paste0(a,"*a"),
                   channel = "alpha")
}
#### Create data to define images/position ####
dat <- data.frame(x=rep(1,2), 
                  y=rep(1,2), 
                  image = c(here::here("inst/hex/brain2.png"),
                            here::here("inst/hex/gene1.png")),
                  size = c(1, .5),
                  alpha = c(.5, 1))
## Make sure the gene is placed behind the brain
dat$image <- factor(x = dat$image, 
                    labels = rev(unique(dat$image)), 
                    ordered = TRUE)
#### Create plot ####
gp <-  ggplot(data=dat, 
              aes(x=x, y=y)) +  
  ggimage::geom_image(aes(image=image,
                          size=I(size), alpha=I(alpha))) + 
  theme_void() 
print(gp)

hexSticker

s_size = .7
stick <- hexSticker::sticker( 
  subplot = here::here("inst/hex/hpo_plotly.png"),
  #### Package name ####
  package = pkg, p_size=20, p_y = 1, p_color = ggplot2::alpha("white",.8),
  #### Subplot #####
  s_x=1, s_y=.9,  s_height = s_size, s_width = s_size,
  #### Fill & border ####
  h_fill = "#0F1941", h_color = "#0e326d",
  #### Spotlight #### 
  spotlight = FALSE, l_alpha = .3, l_width = 10,
  #### File output ####
  filename = filename, dpi = 300, white_around_sticker = TRUE)
print(stick)

Session Info

utils::sessionInfo()



neurogenomics/HPOExplorer documentation built on July 17, 2024, 3:12 p.m.