Non-random allocation of tiles
library(ggplot2) library(dplyr) library(MexBrewer) library(sf) library(truchet)
Create data frame for the mosaic:
xlim <- c(0, 10) ylim <- c(0, 10) # Create a data frame with the spots for tiles container <- expand.grid(x = seq(xlim[1], xlim[2], 1), y = seq(ylim[1], ylim[2], 1)) %>% mutate(tiles = case_when(x <= 2 | x >= 8 ~ "dl", x > 2 & x <8 ~ "dr"), scale_p = case_when(x <= 2 | x >= 8 ~ 1/2, x > 2 & x < 8 ~ 1))
st_truchet_ms(df = container) %>% ggplot() + geom_sf(aes(fill = factor(color)), color = NA)
Create data frame for the mosaic:
xlim <- c(0, 10) ylim <- c(0, 10) # Create a data frame with the spots for tiles container <- expand.grid(x = seq(xlim[1], xlim[2], 1), y = seq(ylim[1], ylim[2], 1)) %>% mutate(tiles = sample(c("fnw", "fne", "fsw", "fse"), n(), replace = TRUE), scale_p = case_when((x < 1 | x > 9) | (y < 1 | y > 9) ~ 1/2, (x > 1 & x < 9) & (y > 1 & y < 9) ~ 1, TRUE ~ 1/2))
Create mosaic using the designed container:
mosaic <- st_truchet_ms(df = container)
Plot mosaic:
ggplot() + geom_sf(data = mosaic, aes(fill = color), color = NA)
Dissolve edges:
mosaic_dissolved <- st_truchet_dissolve(mosaic)
Plot mosaic:
ggplot() + geom_sf(data = mosaic_dissolved, aes(fill = color), color = "white", size = 0.01)
Buffers:
mosaic_buffered_0 <- mosaic_dissolved %>% filter(color == 1) %>% st_buffer(dist = c(-0.05)) %>% mutate(color = 0) mosaic_buffered_1 <- mosaic_dissolved %>% filter(color == 2) %>% st_buffer(dist = c(-0.15)) %>% mutate(color = 3) mosaic_buffered_2 <- mosaic_dissolved %>% filter(color == 2) %>% st_buffer(dist = c(-0.10)) %>% mutate(color = 4) mosaic_buffered_3 <- mosaic_dissolved %>% filter(color == 2) %>% st_buffer(dist = c(-0.05)) %>% mutate(color = 5)
ggplot() + geom_sf(data = mosaic_dissolved, aes(fill = color), color = "black", size = 0.01) + geom_sf(data = mosaic_buffered_0, aes(fill = color), color = "black", size = 0.01) + geom_sf(data = mosaic_buffered_3, aes(fill = color), color = "black", size = 0.01) + geom_sf(data = mosaic_buffered_2, aes(fill = color), color = "black", size = 0.01) + geom_sf(data = mosaic_buffered_1, aes(fill = color), color = "black", size = 0.01) + scale_fill_distiller(palette = "RdYlBu", direction = -1) + theme_void() + theme(legend.position = "none") ggsave("buffered-tiles.png", height = 8, width = 8, units = "in", dpi = 320)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.