Created
May 11, 2020 20:51
-
-
Save sharlagelfand/79827b4bc03d034b3c975dbe0ee0df58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyr) | |
library(dplyr) | |
library(forcats) | |
library(purrr) | |
library(magick) | |
items <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-05-05/items.csv") | |
flowers <- items %>% | |
filter(category == "Flowers") %>% | |
distinct(name, image_url) %>% | |
separate(name, into = c("colour", "flower")) %>% | |
filter(flower != "Tulip") %>% | |
mutate( | |
colour = fct_relevel(colour, c("White", "Yellow", "Green", "Orange", "Pink", "Red", "Purple", "Blue", "Black", "Gold")), | |
flower = fct_relevel(flower, c("Hyacinths", "Roses", "Cosmos", "Lilies", "Windflowers", "Pansies", "Tulips", "Mums")) | |
) %>% | |
arrange(colour, flower) | |
size <- 50 | |
flowers <- flowers %>% | |
mutate( | |
image = map(image_url, image_read), | |
image = map(image, image_scale, size) | |
) | |
n_each <- 10 | |
field <- magick::image_blank( | |
height = size * nrow(flowers), | |
width = size * n_each, | |
col = "#5FB35D" | |
) | |
for (i in 1:nrow(flowers)) { | |
image <- flowers[i, ][["image"]][[1]] | |
for (o in 1:n_each) { | |
field <- image_composite(field, image, offset = paste0("+", size * (o - 1), "+", size * (i - 1))) | |
} | |
} | |
field |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment