| name | hex-logo |
| description | Create professional hexagonal package logos using hexSticker with Google Fonts, proper dimensions, and automated generation scripts |
Hexagonal Package Logo Creation
This skill covers creating professional hexagonal package logos using the hexSticker package. Hex logos are the standard branding for R packages, featured on package websites, GitHub repos, and CRAN pages.
Rules
- Standard dimensions: 5.08cm x 4.39cm (2 x 1.73 inches) for consistency
- Use hexSticker package for proper proportions and formatting
- Generate with script in man/figures/generate_logo.R (reproducible)
- Exclude script from build via .Rbuildignore
- Output both PNG and SVG formats (PNG for README, SVG for print)
- Use Google Fonts with showtext for custom typography
- Match package identity with appropriate colors and imagery
- Keep it simple - logos should work at small sizes
- Add to README with proper alignment and alt text
- Version control logos (commit PNG/SVG, not temporary files)
Installation and Setup
Required Packages
install.packages("hexSticker")
install.packages("showtext")
install.packages("ggplot2")
install.packages("magick")
library(hexSticker)
library(showtext)
library(ggplot2)
Standard Hex Dimensions
Official Specifications
- Width: 5.08 cm (2 inches)
- Height: 4.39 cm (1.73 inches)
- Aspect ratio: ~1.15:1
- DPI: 300 for print, 72 for web (hexSticker uses default appropriate for each)
These are set automatically by hexSticker.
Basic Hex Sticker Creation
Minimal Example (Text Only)
library(hexSticker)
sticker(
subplot = ~ plot.new(),
package = "mypackage",
p_size = 20,
p_color = "#FFFFFF",
h_fill = "#0054AD",
h_color = "#000000",
filename = "man/figures/logo.png"
)
With Image Subplot
library(hexSticker)
img_path <- "man/figures/icon.png"
sticker(
subplot = img_path,
s_x = 1,
s_y = 0.75,
s_width = 0.6,
s_height = 0.6,
package = "mypackage",
p_size = 20,
p_y = 1.45,
p_color = "#FFFFFF",
h_fill = "#0054AD",
h_color = "#000000",
filename = "man/figures/logo.png"
)
With ggplot2 Subplot
library(hexSticker)
library(ggplot2)
p <- ggplot(mtcars, aes(mpg, wt)) +
geom_point(color = "white", size = 2) +
theme_void() +
theme_transparent()
sticker(
subplot = p,
s_x = 1,
s_y = 0.85,
s_width = 1.3,
s_height = 1,
package = "mypackage",
p_size = 20,
p_y = 1.5,
p_color = "#FFFFFF",
h_fill = "#0054AD",
h_color = "#FFFFFF",
h_size = 1.5,
filename = "man/figures/logo.png",
dpi = 300
)
Google Fonts Integration
Using showtext for Custom Fonts
library(hexSticker)
library(showtext)
font_add_google("Fira Sans", "firasans")
font_add_google("Fira Code", "firacode")
showtext_auto()
sticker(
subplot = ~ plot.new(),
package = "mypackage",
p_size = 24,
p_family = "firasans",
p_fontface = "bold",
p_color = "#FFFFFF",
h_fill = "#0054AD",
h_color = "#000000",
filename = "man/figures/logo.png",
dpi = 300
)
Popular Font Combinations
font_add_google("Inter", "inter")
font_add_google("JetBrains Mono", "jetbrains")
font_add_google("Roboto", "roboto")
font_add_google("Roboto Slab", "robotoslab")
font_add_google("Nunito", "nunito")
font_add_google("Quicksand", "quicksand")
font_add_google("Fira Sans", "firasans")
font_add_google("Fira Code", "firacode")
font_add_google("Lato", "lato")
font_add_google("Merriweather", "merriweather")
font_add_google("Montserrat", "montserrat")
font_add_google("Bebas Neue", "bebas")
Complete Generation Script Template
man/figures/generate_logo.R
library(hexSticker)
library(showtext)
library(ggplot2)
PACKAGE_NAME <- "mypackage"
OUTPUT_DIR <- "man/figures"
if (!dir.exists(OUTPUT_DIR)) {
dir.create(OUTPUT_DIR, recursive = TRUE)
}
font_add_google("Fira Sans", "firasans")
showtext_auto()
FILL_COLOR <- "#0054AD"
BORDER_COLOR <- "#000000"
TEXT_COLOR <- "#FFFFFF"
ACCENT_COLOR <- "#FFA500"
set.seed(123)
plot_data <- data.frame(
x = rnorm(100),
y = rnorm(100)
)
p <- ggplot(plot_data, aes(x, y)) +
geom_point(color = TEXT_COLOR, alpha = 0.6, size = 1.5) +
geom_density_2d(color = ACCENT_COLOR, size = 0.8) +
theme_void() +
theme_transparent() +
theme(
legend.position = "none",
panel.background = element_rect(fill = "transparent", color = NA),
plot.background = element_rect(fill = "transparent", color = NA)
)
sticker(
subplot = p,
s_x = 1,
s_y = 0.85,
s_width = 1.4,
s_height = 1.1,
package = PACKAGE_NAME,
p_size = 20,
p_family = "firasans",
p_fontface = "bold",
p_color = TEXT_COLOR,
p_y = 1.5,
h_fill = FILL_COLOR,
h_color = BORDER_COLOR,
h_size = 1.5,
url = "github.com/username/mypackage",
u_size = 3.5,
u_color = TEXT_COLOR,
u_family = "firasans",
filename = file.path(OUTPUT_DIR, "logo.png"),
dpi = 300
)
sticker(
subplot = p,
s_x = 1,
s_y = 0.85,
s_width = 1.4,
s_height = 1.1,
package = PACKAGE_NAME,
p_size = 20,
p_family = "firasans",
p_fontface = "bold",
p_color = TEXT_COLOR,
p_y = 1.5,
h_fill = FILL_COLOR,
h_color = BORDER_COLOR,
h_size = 1.5,
url = "github.com/username/mypackage",
u_size = 3.5,
u_color = TEXT_COLOR,
u_family = "firasans",
filename = file.path(OUTPUT_DIR, "logo.svg")
)
message("Logo generated successfully:")
message(" PNG: ", file.path(OUTPUT_DIR, "logo.png"))
message(" SVG: ", file.path(OUTPUT_DIR, "logo.svg"))
Make Script Executable
chmod +x man/figures/generate_logo.R
Exclude from Package Build
Add to .Rbuildignore:
^man/figures/generate_logo\.R$
Or use usethis:
usethis::use_build_ignore("man/figures/generate_logo.R")
Comprehensive Parameter Reference
sticker() Parameters
Subplot Parameters
- subplot: Image path, ggplot object, or expression (required)
- s_x: Horizontal position (default: 1, center)
- s_y: Vertical position (default: 0.75)
- s_width: Width scaling (default: 0.4)
- s_height: Height scaling (default: 0.4)
Package Name Parameters
- package: Package name string
- p_x: Horizontal position (default: 1, center)
- p_y: Vertical position (default: 1.4, bottom)
- p_size: Font size (default: 8)
- p_color: Text color (default: "#FFFFFF")
- p_family: Font family (default: "sans")
- p_fontface: Font face: "plain", "bold", "italic", "bold.italic"
Hex Parameters
- h_fill: Fill color (default: "#1881C2")
- h_color: Border color (default: "#87B13F")
- h_size: Border width (default: 1.2)
Spotlight/White Space Parameters
- spotlight: Add spotlight effect (default: FALSE)
- l_x: Spotlight horizontal position
- l_y: Spotlight vertical position
- l_width: Spotlight width
- l_height: Spotlight height
- l_alpha: Spotlight transparency (0-1)
URL Parameters
- url: URL text to display at bottom
- u_x: URL horizontal position (default: 1)
- u_y: URL vertical position (default: 0.08)
- u_size: URL font size (default: 1.5)
- u_color: URL text color (default: "black")
- u_family: URL font family
- u_angle: URL text angle (default: 30)
Output Parameters
- filename: Output file path (required)
- dpi: Resolution for PNG (default: 300)
- asp: Aspect ratio override (usually omit)
Color Scheme Guidelines
Choosing Colors
Brand colors: Match your organization/project colors
Contrast: Ensure text is readable on background
Color theory:
- Complementary: Opposite on color wheel (high contrast)
- Analogous: Adjacent on color wheel (harmonious)
- Triadic: Three evenly spaced colors (balanced)
Color Palette Examples
h_fill = "#1881C2"
h_color = "#87B13F"
p_color = "#FFFFFF"
h_fill = "#0054AD"
h_color = "#003366"
p_color = "#FFFFFF"
h_fill = "#DC3545"
h_color = "#8B0000"
p_color = "#FFFFFF"
h_fill = "#28A745"
h_color = "#155724"
p_color = "#FFFFFF"
h_fill = "#6F42C1"
h_color = "#3D1F6B"
p_color = "#FFFFFF"
h_fill = "#FD7E14"
h_color = "#A04100"
p_color = "#FFFFFF"
h_fill = "#212529"
h_color = "#000000"
p_color = "#FFFFFF"
h_fill = "#F8F9FA"
h_color = "#000000"
p_color = "#212529"
Accessibility
Ensure sufficient contrast (WCAG AA standard: 4.5:1 for normal text):
h_fill = "#0054AD"; p_color = "#FFFFFF"
h_fill = "#FFFFFF"; p_color = "#000000"
h_fill = "#FFD700"; p_color = "#FFFFFF"
h_fill = "#87CEEB"; p_color = "#FFFFFF"
Advanced Examples
Logo with Custom Icon
library(hexSticker)
library(showtext)
library(magick)
icon <- image_read("man/figures/custom_icon.png")
icon <- image_transparent(icon, "white")
icon <- image_trim(icon)
image_write(icon, "man/figures/icon_processed.png")
font_add_google("Fira Sans", "firasans")
showtext_auto()
sticker(
subplot = "man/figures/icon_processed.png",
s_x = 1,
s_y = 0.85,
s_width = 0.5,
s_height = 0.5,
package = "mypackage",
p_size = 22,
p_family = "firasans",
p_fontface = "bold",
p_color = "#FFFFFF",
p_y = 1.45,
h_fill = "#0054AD",
h_color = "#003366",
h_size = 1.5,
url = "mypackage.com",
u_size = 3,
u_color = "#FFFFFF",
filename = "man/figures/logo.png",
dpi = 300
)
Logo with Spotlight Effect
library(hexSticker)
sticker(
subplot = ~ plot.new(),
package = "mypackage",
p_size = 24,
p_color = "#FFFFFF",
p_y = 1,
h_fill = "#0054AD",
h_color = "#000000",
spotlight = TRUE,
l_x = 1,
l_y = 0.8,
l_width = 3,
l_height = 3,
l_alpha = 0.3,
filename = "man/figures/logo.png"
)
Statistical Visualization Logo
library(hexSticker)
library(ggplot2)
library(showtext)
font_add_google("Roboto", "roboto")
showtext_auto()
set.seed(42)
df <- data.frame(
x = rep(1:10, each = 10),
y = rep(1:10, times = 10),
z = rnorm(100)
)
p <- ggplot(df, aes(x, y, fill = z)) +
geom_tile() +
scale_fill_gradient2(
low = "#0054AD",
mid = "#FFFFFF",
high = "#DC3545",
midpoint = 0
) +
theme_void() +
theme_transparent() +
theme(legend.position = "none")
sticker(
subplot = p,
s_x = 1,
s_y = 0.8,
s_width = 1.2,
s_height = 1,
package = "heatmapR",
p_size = 18,
p_family = "roboto",
p_fontface = "bold",
p_color = "#000000",
p_y = 1.55,
h_fill = "#F8F9FA",
h_color = "#000000",
h_size = 1.5,
filename = "man/figures/logo.png",
dpi = 300
)
Network Visualization Logo
library(hexSticker)
library(ggplot2)
library(ggraph)
library(igraph)
library(showtext)
font_add_google("Montserrat", "montserrat")
showtext_auto()
set.seed(123)
g <- erdos.renyi.game(15, 0.3)
p <- ggraph(g, layout = "fr") +
geom_edge_link(color = "white", alpha = 0.5, width = 0.5) +
geom_node_point(color = "#FFA500", size = 3) +
theme_void() +
theme_transparent()
sticker(
subplot = p,
s_x = 1,
s_y = 0.85,
s_width = 1.3,
s_height = 1.1,
package = "netanalysis",
p_size = 16,
p_family = "montserrat",
p_fontface = "bold",
p_color = "#FFFFFF",
p_y = 1.5,
h_fill = "#0054AD",
h_color = "#000000",
h_size = 1.5,
filename = "man/figures/logo.png",
dpi = 300
)
Adding Logo to README
Standard README Header
# mypackage <img src="man/figures/logo.png" align="right" height="139" alt="" />
<!-- badges: start -->
[](https://github.com/username/mypackage/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
Brief description of your package.
## Installation
You can install the development version of mypackage from GitHub:
```r
# install.packages("devtools")
devtools::install_github("username/mypackage")
**Height specification**: 139 pixels is standard (1/5 of typical hex height)
### Alternative: Center Logo
```markdown
<div align="center">
<img src="man/figures/logo.png" width="200" alt="mypackage logo">
<h1>mypackage</h1>
<p>Brief tagline</p>
</div>
Common Pitfalls
1. Logo Not Showing on GitHub
Problem: Logo displays locally but not on GitHub
Fix:
- Commit logo files:
git add man/figures/logo.png
- Use relative path:
man/figures/logo.png (not absolute)
- Check file exists in repository
2. Poor Text Readability
Problem: Package name is hard to read at small sizes
Fix:
- Increase font size:
p_size = 24 or higher
- Use bold font:
p_fontface = "bold"
- Ensure high contrast between text and background
- Avoid decorative fonts for package name
3. Image Subplot Off-Center
Problem: Icon or plot is positioned incorrectly
Fix: Adjust position parameters:
s_x = 1
s_y = 0.85
Experiment with values to find optimal placement.
4. Fonts Not Rendering
Problem: Google Fonts don't appear in output
Fix:
library(showtext)
showtext_auto()
font_add_google("Font Name", "fontid")
p_family = "fontid"
5. SVG Export Issues
Problem: SVG file has rendering problems
Fix:
- Some complex ggplot2 features don't export well to SVG
- Simplify plot (reduce transparency, gradients)
- Or stick with PNG for complex visualizations
6. Large File Size
Problem: PNG file is >500 KB
Fix:
library(magick)
logo <- image_read("man/figures/logo.png")
logo <- image_resize(logo, "1024x")
logo <- image_write(logo, "man/figures/logo.png", quality = 85)
7. Colors Look Different on Web
Problem: Colors appear different on different screens
Fix:
- Use web-safe colors
- Test on multiple devices
- Use hex color codes consistently
- Avoid very saturated colors
8. Logo Dimensions Wrong
Problem: Logo is squashed or stretched
Fix: Don't override aspect ratio - hexSticker handles this automatically. Remove any asp parameter.
9. URL Text Unreadable
Problem: URL at bottom is too small or angled
Fix:
u_size = 4
u_angle = 0
u_color = "#FFFFFF"
10. Subplot Cuts Off
Problem: Image or plot is clipped at edges
Fix:
s_width = 0.5
s_height = 0.5
Automation and Reproducibility
Makefile Integration
Create Makefile:
.PHONY: logo clean
logo:
Rscript man/figures/generate_logo.R
clean:
rm -f man/figures/logo.png man/figures/logo.svg
Usage:
make logo
make clean
GitHub Actions
Add to .github/workflows/logo.yaml:
name: Update Logo
on:
push:
paths:
- 'man/figures/generate_logo.R'
jobs:
update-logo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
- name: Install dependencies
run: |
install.packages(c("hexSticker", "showtext", "ggplot2"))
shell: Rscript {0}
- name: Generate logo
run: Rscript man/figures/generate_logo.R
- name: Commit logo
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add man/figures/logo.png man/figures/logo.svg
git commit -m "Update logo" || echo "No changes"
git push
Logo Variations
Different Output Sizes
sticker(..., filename = "man/figures/logo.png", dpi = 300)
sticker(..., filename = "man/figures/logo_large.png", dpi = 600)
library(magick)
img <- image_read("man/figures/logo.png")
img_thumb <- image_resize(img, "256x256")
image_write(img_thumb, "man/figures/logo_256.png")
White Border Version
sticker(..., h_fill = "#000000", p_color = "#FFFFFF")
sticker(..., h_fill = "#FFFFFF", p_color = "#000000", h_color = "#000000")
Creating a professional hex logo enhances your package's visibility and brand recognition!