Created
January 27, 2019 01:52
-
-
Save djnavarro/3a5a45a39209ae96816b9e9eaef38cbb to your computer and use it in GitHub Desktop.
This file contains 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
# Adapted from Claus Wilke's code | |
# https://github.com/clauswilke/isoband | |
library(isoband) | |
library(magick) | |
library(sf) | |
library(tidyverse) | |
# my twitter profile | |
img_loc <- "https://pbs.twimg.com/profile_images/1088575199568584704/zGiMgFB7_400x400.jpg" | |
sf_from_image <- function(image) { | |
image_gray <- image %>% image_quantize(colorspace = "gray") | |
image_raster <- as.raster(image_gray) | |
d <- dim(image_raster) | |
m <- matrix(c((255-col2rgb(image_raster)[1,])), nrow = d[1], ncol = d[2], byrow = TRUE) | |
b <- isobands(1:d[2], d[1]:1, m, 20*(0:13), 20*(1:14)) | |
bands <- iso_to_sfg(b) | |
data <- st_sf( | |
level = letters[1:length(bands)], | |
geometry = st_sfc(bands) | |
) | |
} | |
img <- image_resize(image_read(img_loc), "200x200") | |
img_sf <- sf_from_image(img) | |
# p1 <- ggplot(img_sf) + | |
# geom_sf(color = "gray10", fill = NA, size = 0.05) + | |
# coord_sf(expand = FALSE) + | |
# theme_gray() + | |
# theme( | |
# axis.ticks = element_blank(), | |
# axis.text = element_blank(), | |
# axis.title = element_blank(), | |
# axis.ticks.length = grid::unit(0, "pt"), | |
# plot.margin = margin(0, 0, 0, 0) | |
# ) | |
# nice <- c("berlin", "bilbao", "grayC", "lajolla", "lisbon") | |
# for( palettechoice in nice ) { | |
# p2 <- ggplot(img_sf) + | |
# geom_sf(aes(fill = level, color = level), show.legend = FALSE) + | |
# coord_sf(expand = FALSE) + | |
# scale_fill_scico_d(palette = palettechoice) + | |
# scale_color_scico_d(palette = palettechoice) + | |
# theme_void() | |
# | |
# ggsave(paste0("C:/Users/Dan/Desktop/danielle_",palettechoice,".png")) | |
# } | |
#plot(p2) | |
p3 <- ggplot(img_sf) + | |
geom_sf(aes(fill = level, color = level), size = 0.1) + | |
scale_fill_hue( | |
aesthetics = c("color", "fill"), | |
guide = "none", l = 70, c = 90) + | |
coord_sf(expand = FALSE) + | |
theme_void() | |
ggsave("C:/Users/Dan/Desktop/danielle_hue.png") | |
plot(p3) |
Author
djnavarro
commented
Jan 27, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment