---
title: "hexSticker"
author: "<h4>Author: <i>Brian M. Schilder</i></h4>" 
date: "<h4>Most recent update: <i>`r format( Sys.Date(), '%b-%d-%Y')`</i></h4>"
output: rmarkdown::html_vignette
editor_options: 
  chunk_output_type: inline
vignette: >
  %\VignetteIndexEntry{hexSticker}
  %\VignetteEncoding{UTF-8}
  %\VignetteEngine{knitr::rmarkdown}
---

```{r, include = FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.width = 7, fig.height = 5, root.dir=here::here())
knitr::opts_knit$set(root.dir=here::here())
```

You can make awesome hex stickers for your R packages using [hexSticker](https://github.com/GuangchuangYu/hexSticker). 

# orthogene

Silhouettes from [phylopic](http://phylopic.org/). 

[ggimage](https://github.com/GuangchuangYu/ggimage) let's you render images as data points.

[ggpattern](https://coolbutuseless.github.io/package/ggpattern/) lets you fill objects with patterns or images.


```{r, eval=FALSE}
library(hexSticker)
library(dplyr)
library(ggplot2)
library(ggimage)
library(ggpattern)# remotes::install_github("coolbutuseless/ggpattern")
library(ggplot2)

get_url <- function(uuid){
    attr(rphylopic::get_phylopic(uuid=uuid), "url")
}



image_info <- data.frame(
    image=c(
        get_url(uuid="c089caae-43ef-4e4e-bf26-973dd4cb65c5"), # Human  
        get_url(uuid="eedde61f-3402-4f7c-9350-49b74f5e1dba"), # Macaque
        get_url(uuid="c8f71c27-71db-4b34-ac2d-e97fea8762cf"), # Mouse
        get_url(uuid="e86bc377-3a6c-4efa-8703-1a12cb019ef7"), # Zebrafish
        get_url(uuid="b5160ba3-ad86-4123-92a7-1c55122f4a6c"), # Fly
        get_url(uuid="d6af4346-e56c-4f3d-84c7-fba921a293f1") # Worm
    ),
                
                species = c("Human", "Macaque", "Mouse",
                            "Zebrafish", "Fly","Worm"
                            ),
                size=c(.5,1,1.1, 
                       1.1,1.1,1)/5,
                alpha=c(.8,.8,1,
                        .8,.8,1)
                ) 

for (i in 1:nrow(image_info)){
    row = image_info[i,]
    download.file(row$image, 
                  here::here("inst/hex/silhouettes",paste0(row$species,".svg")))
}
image_info <- rbind(image_info, image_info[1,] |> dplyr::mutate(size=0))

### From ggimage code
polygon_df <- dplyr::tibble(
  angle = seq(0, 2*pi, length.out = 7) + pi/6,
  x     = cos(angle),
  y     = sin(angle)
)
polygon_df2 <- dplyr::tibble(
  angle = seq(0, 2*pi, length.out = 7) + pi/6,
  x     = cos(angle)*1.25,
  y     = sin(angle)*1.25
)


d <- cbind(polygon_df, image_info)

hex_species <- ggplot(d, aes(x, y)) + 
   ggpattern::geom_polygon_pattern(data = polygon_df2,
                                   pattern= 'image',
                                   aes(x=I(x/1), y=I(y/1)),
                                   pattern_type = 'expand',
    pattern_filename = here::here("inst/hex/purple_blue.jpeg"), 
    inherit.aes = FALSE) +  
   geom_path(color="white", size = .8, alpha=.5) +
   geom_path(color="white", size=.5, alpha=.5) +
   geom_path(color="white", size=.1, alpha=5) +  
   # geom_image(aes(image=image), size=.12, color="white", alpha=.5) +
   # geom_image(aes(image=image), size=.11, color="white", alpha=.5) +
   geom_image(aes(image=image, x=I(x/1), y=I(y/1), size=I(size), alpha=I(alpha)), color="white") +
   theme_void()

s_width <- 1.6
s <- sticker(hex_species,
          package="orthogene", p_size=10, p_y = 1,
          s_x=1, s_y=1, s_width=s_width, s_height=s_width*1.11111, 
          h_color = "black", h_fill = "#330862",white_around_sticker = TRUE,
          filename=here::here("inst/hex/hex.png"), dpi = 400)

print(s)
```


```
R -q -e 'remove.packages("magick")'

export PATH="/opt/homebrew/bin:$PATH"
export PKG_CONFIG_PATH="/opt/homebrew/lib/pkgconfig"

brew install imagemagick@6
R -q -e 'options(repos=c(CRAN="https://cloud.r-project.org")); install.packages("magick", type="source")'
```


# Session Info 

<details> 

```{r Session Info}
utils::sessionInfo()
```

</details>  

