Last active
January 7, 2020 23:06
-
-
Save MirzaCengic/34b711d94bfcb21f3d394be0b13ac322 to your computer and use it in GitHub Desktop.
Elevation map in the style of Joy Division's Unknown Pleasures
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
# Elevation lines map for the #30DayMapChallenge | |
# Author: Mirza Čengić | [email protected] | |
pacman::p_load(Rahat, tidyverse, raster, topo.ridges) | |
raster_bih <- getData(name = "alt", country = "BA") | |
raster_bih_agg <- aggregate(raster_bih, fact = 5) | |
raster_bih_agg[is.na(raster_bih_agg)] <- 0 | |
my_dat <- cbind(coordinates(raster_bih_agg), values(raster_bih_agg)) %>% | |
as.data.frame() %>% | |
transmute( | |
x, y, | |
val = V3 | |
) | |
#### | |
# standardize values for easier visualization | |
range01 <- function(x) | |
{ | |
( x - min(x)) / (max(x)-min(x)) | |
} | |
my_dat$val[is.na(my_dat$val)] <- 0 | |
my_dat$val_st <- range01(my_dat$val)*0.08 # peakiness of lines | |
my_dat$x_st <- range01(my_dat$x) | |
my_dat$y_st <- range01(my_dat$y) | |
my_dat$ord <- my_dat$y | |
my_dat_s <- my_dat[order(-my_dat$ord),] | |
p_lines <- ggplot() + | |
geom_path( | |
data = my_dat_s, | |
# data = aa, | |
aes(x = x_st, y = val_st + y_st, group = y_st), size = 0.75, | |
col = "white") + | |
labs( | |
title = "BOSNIA&HERZEGOVINA", | |
caption = "ELEVATION LINES" | |
) + | |
theme( | |
# axis.text = element_text(color = "white"), | |
plot.background = element_rect(fill = 'black', colour = 'black'), | |
panel.background = element_rect(fill = 'black', colour = 'black'), | |
panel.grid = element_blank(), | |
axis.text = element_blank(), | |
axis.ticks = element_blank(), | |
# axis.text = element_blank(), | |
panel.border = element_blank(), | |
plot.title = element_text(color = "white", family = "Helvetica", | |
size = 43, | |
# face = "bold", | |
vjust = -1, | |
hjust = 0.5), | |
plot.caption = element_text(color = "white", family = "Helvetica", | |
size = 40, | |
# face = "bold", | |
vjust = 1, | |
hjust = 0.5) | |
) + | |
annotate("text", x = 0.89, y = -0.03, label = "@mirzacengic | itsprettydata.com", color = "white", | |
family = "Helvetica-Narrow", size = 2.3) | |
p_lines | |
ggsave("/home/mirza/Projects/mapvember/02_lines/02_lines_new.png", p_lines) | |
library(svglite) | |
ggsave(file="/home/mirza/Projects/mapvember/02_lines/02_lines.svg", plot=p_lines, width=10, height=8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment