Skip to content

Instantly share code, notes, and snippets.

@andrewbtran
Last active March 2, 2023 17:06
Show Gist options
  • Save andrewbtran/07bd3abd4eb3a958c00af99c1d306baf to your computer and use it in GitHub Desktop.
Save andrewbtran/07bd3abd4eb3a958c00af99c1d306baf to your computer and use it in GitHub Desktop.
wpdatateam logo generator
# code from https://github.com/gkaramanis/aRtist/blob/main/genuary/2021/2021-3/2021-3.R
library(ggplot2)
library(dplyr)
library(magick)
library(ggridges)
# Read in image and convert to grayscale
img <- image_read(here::here("MRlWzfMH_400x400.jpg")) %>%
image_convert(colorspace = "gray")
# Get dimensions
img_w <- image_info(img)$width
img_h <- image_info(img)$height
img_ratio <- img_w / img_h
# Resize the longest dimension to 160 pixels
if (img_w >= img_h) {
img <- image_resize(img, "100")
} else {
img <- image_resize(img, ("x100"))
}
# Create array and number rows and columns
img_array <- drop(as.integer(img[[1]]))
rownames(img_array) <- 1:nrow(img_array)
colnames(img_array) <- 1:ncol(img_array)
# Create data frame from array and rename columns
img_df <- as.data.frame.table(img_array) %>%
`colnames<-`(c("y", "x", "b")) %>%
mutate(
across(everything(), as.numeric),
n = row_number()
) %>%
filter(n %% 2 == 0)
# Colors, fill and background
col_fill <- "black"
col_bg <- "white"
plotted <- ggplot(img_df) +
geom_ridgeline_gradient(aes(x, y, height = b/50, group = y, fill = b), color = "#D85218", size = .25) +
scale_y_reverse() +
scale_fill_gradient(low = "#306624", high = "white")+
coord_cartesian(expand = FALSE) +
theme_void() +
theme(
legend.position = "none",
plot.background = element_rect(fill = col_fill, color = NA)
)
plotted
ggsave(here::here("wpdatateam-ridge.png"), plotted, dpi = 320, width = 7, height = 7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment