-
Notifications
You must be signed in to change notification settings - Fork 4
/
hexSticker.Rmd
109 lines (88 loc) Β· 3.56 KB
/
hexSticker.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
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}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{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)
pBase <- "http://phylopic.org/assets/images/submissions"
image_info <- data.frame(
image = file.path(pBase,
c("c089caae-43ef-4e4e-bf26-973dd4cb65c5.512.png",# Human
"eedde61f-3402-4f7c-9350-49b74f5e1dba.512.png", # Macaque
"c8f71c27-71db-4b34-ac2d-e97fea8762cf.original.png", # Mouse
"6f4c653a-1da1-4e02-85ef-6344b2d8e02a.512.png", # Zebrafish
"ea8fa530-d856-4423-a81d-a74342cd1875.512.png", # Fly
"d6af4346-e56c-4f3d-84c7-fba921a293f1.512.png" # 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)
)
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/images/purple_blue.jpeg"),
inherit.aes = FALSE) +
geom_path(color="white", size = .8, alpha=.1) +
geom_path(color="white", size=.5, alpha=.5) +
geom_path(color="white", size=.1, alpha=1) +
# geom_image(aes(image=image), size=.12, color="white", alpha=.1) +
# geom_image(aes(image=image), size=.11, color="white", alpha=.2) +
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=20, 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)
```
# Session Info
<details>
```{r Session Info}
utils::sessionInfo()
```
</details>