briatte / ggnetwork

Geoms to plot networks with ggplot2
https://briatte.github.io/ggnetwork/
146 stars 28 forks source link

A hex logo suggestion (in R with the code) #44

Closed mcanouil closed 4 years ago

mcanouil commented 5 years ago

Here is an hexlogo suggestion using ggnetwork to build it (and some other packages). Of course, everything can be changed.

set.seed(190723)
library(ggplot2)
library(hexSticker)
library(ggnetwork)
library(network)
library(sna)
library(showtext)

word <- "ggnetwork"
n <- network(rgraph(9, tprob = 0.2), directed = FALSE)
n %v% "family" <- strsplit(word, "")[[1]][c(1, 7, 9, 5, 4, 8, 3, 6, 2)]
n %v% "importance" <- sample(x = 1:4, size = nchar(word), replace = TRUE)
e <- network.edgecount(n)
set.edge.attribute(n, "type", sample(letters[23:26], e, replace = TRUE))
set.edge.attribute(n, "day", sample(1:4, e, replace = TRUE))

font_add_google("Alegreya SC", "alegreyasc")
showtext_auto()

sticker(
  subplot = ggplot(n, aes(x = x, y = y, xend = xend, yend = yend)) +
    geom_edges(colour = "grey50", alpha = 0.5) +
    geom_nodes(aes(colour = family, size = 0.5 * importance), alpha = 1) +
    geom_nodes(aes(colour = family, size = importance), alpha = 0.5) +
    geom_nodetext(
      aes(label = toupper(family)), 
      size = 1 * 5,
      fontface = "bold", 
      family = "alegreyasc"
    ) +
    scale_colour_brewer(palette = "Set1") +
    scale_size(breaks = c(1, 2), range = c(1, 2) * 3) +
    scale_x_continuous(expand = expand_scale(mult = 0.2)) +
    scale_y_continuous(expand = expand_scale(mult = 0.2)) +
    theme_blank() +
    theme(
      legend.position = "none",
      panel.background = ggplot2::element_rect(fill = NA, colour = NA), 
      plot.background = ggplot2::element_rect(fill = NA, colour = NA)
    ), 
  package = "ggnetwork", 
  p_size = 18, 
  p_color = "grey20", 
  p_family = "alegreyasc",
  p_y = 1.5,
  s_x = 1, 
  s_y = 0.80, 
  s_width = 1.5, 
  s_height = 1.5,
  filename = "~/ggnetwork.png",
  h_fill = "grey95", 
  h_color = "grey20"
)

briatte commented 4 years ago

Closing this one -- thank you very much for the suggestion, but I must say that I'm not really into the logo and sticker thing.