Capítulo24 Hex Stickers

## [1] "2025-10-29"
library(hexSticker) 
library(magick)
library(sysfonts)
library(tidyverse)

24.1 La función y los valores “default”

sticker(
  subplot, # position and size of subplot
  s_x = 0.8,
  s_y = 0.75,
  s_width = 0.4,
  s_height = 0.5,
  package, # package name and characteristics
  p_x = 1,
  p_y = 1.4,
  p_color = "#FFFFFF",
  p_family = "Aller_Rg",
  p_fontface = "plain",
  p_size = 8,
  h_size = 1.2, # hexagon border size and colors
  h_fill = "#1881C2",
  h_color = "#87B13F",
  spotlight = FALSE,
  l_x = 1, # spotlight x position
  l_y = 0.5,
  l_width = 3,
  l_height = 3,
  l_alpha = 0.4,
  url = "", # url at lower border
  u_x = 1,
  u_y = 0.08,
  u_color = "black",
  u_family = "Aller_Rg",
  u_size = 1.5,
  u_angle = 30,
  white_around_sticker = FALSE, # if TRUE, puts white triangles in the corners
  ...,
  filename = paste0(package, ".png"), # filename to save sticker
  asp = 1, # aspect ratio, only works if subplot is an image file
  dpi = 300 # plot resolution
)

Arguments

library(gt)
gt(argumentos)
Función Descripción
subplot subplot
s_x x position for subplot
s_y y position for subplot
s_width width for subplot
s_height height for subplot
package package name
p_x x position for package name
p_y y position for package name
p_color color for package name
p_family font family for package name
p_fontface fontface for package name
p_size font size for package name
h_size size for hexagon border
h_fill color to fill hexagon
h_color color for hexagon border
spotlight whether add spotlight
l_x x position for spotlight
l_y y position for spotlight
l_width width for spotlight
l_height height for spotlight
l_alpha maximum alpha for spotlight
url url at lower border
u_x x position for url
u_y y position for url
u_color color for url
u_family font family for url
u_size text size for url
u_angle angle for url
white_around_sticker default to FALSE. If set to TRUE, it puts white triangles in the corners
... additional parameter to geom_pkgname
filename filename to save sticker
asp aspect ratio, only works if subplot is an image file
dpi plot resolution

Other Details, - The extension given in filename determines the graphics device that is used to render the sticker, e.g. filename = ‘sticker.png’ creates a png file and filename = ‘sticker.svg’ creates a svg file. For a list of supported graphics devices please see the documentation of ggplot2::ggsave()

sysfonts::font_add_google(“Sixtyfour Convergence”) sysfonts::font_add_google(“Rubik”) sysfonts::font_add_google(“Young Serif”) ## No baja

24.2 Ejemplo de Crear un Hex con un gatito

#font_files()  #a list of all fonts available

## Loading Google fonts (https://fonts.google.com/)

#sysfonts::font_add_google("Dancing Script") # selección de fonts de google
#sysfonts::font_add_google("Bebas Neue")
#sysfonts::font_add_google("Fuggles")
#sysfonts::font_add_google("Roboto")
#sysfonts::font_add_google("Montserrat")
#sysfonts::font_add_google("Lobster Two")
sysfonts::font_add_google("Monsieur La Doulaise")
#sysfonts::font_add_google("monsieur")



cat_img=image_read('cat.jpg')
analitica_img=image_read('Analitica3.png')



library(showtext)
font_add_google("Monsieur La Doulaise")
showtext_opts(dpi = 300)
showtext_auto()



sticker(
  subplot= cat_img,
  package="Meow \n software",
  s_width =.55,
  s_height = .55,
  s_x=1,
  s_y=.75,
  p_size=8, # tamaño del texto
  p_x = 1.0,
  p_y = 1.5,
  p_color= 'purple',
  p_family= "Monsieur La Doulaise",
  h_fill ='gold',
  h_color='hotpink',
  h_size = 2,
  url="www.cat.foundation.com",
  u_size=4,
  u_color = "violetred",
  spotlight=T

) %>% print

save_sticker("hex_sticker_cat.jpg")