This was a project I made while trying to learn the r programming language. After seeing a bunch of stacked line graphs on r/DataIsBeautiful made with R I decided to try and make my own version to gain a better understanding of the language. The style is based on the Album Cover to Joy Divison’s Unknown Pleasures.

# Import any Packages


if(!require("imager")) {
    install.packages("imager", repos = "https://cran.revolutionanalytics.com")
    library("imager")
}

if(!require("ggplot2")) {
    install.packages("ggplot2", repos = "https://cran.revolutionanalytics.com")
    library("ggplot2")
}

# Load in the image
im <- load.image("joy_division/heightmap.jpg")

This is the heightmap for the graphic we will be using (joy_division/heightmap.jpg)

Original Heightmap

Now if we resample this down to a much smaller number of rows (these will be the lines), but the same amount of columns

num_rows <- 80 # There are 80 rows on the album cover, adjust as necessary
num_columns <- dim(im)[2] # Set the number of columns to be same as image
sample <- 5 # bicubic

data <- resize(im, size_x=num_columns, size_y=num_rows, interpolation_type=sample)

Here is the condensed version of the image (only 80 rows high)

Intermediate Stage

Convert the data to a matrix and normalise

grid <- data[,,1,3]
grid_norm <- (grid-min(grid))/(max(grid)-min(grid))

Boost the y values so that the lines are separate

for(i in 1:num_rows){
    grid_norm[,i] =24 + grid_norm[,i] - 0.3*i
}

Set up the data frame and plot

# Set up the data frame for the plot
data_frame = data.frame(
    row=rep(1:num_rows, each = num_columns),
    height=as.vector(grid_norm),
    acr = rep(1:num_columns,  num_rows)
)

pl <- ggplot(data = data_frame, aes(x=acr, y=height, group=row)) 
https://en.wikipedia.org/wiki/Unknown_Pleasures
pl <- pl + geom_ribbon(aes(ymin=-1, ymax=height),
                                 size=0.3,
                                 colour = "#F0F0F0",
                                 fill = "black"
)

Now, draw over the lines at the sides and bottom of the plot in black, and apply theming

# Now colour out the edges
pl <- pl + geom_hline(yintercept = -1, linetype="solid", color="black", size=1)
pl <- pl + geom_vline(xintercept = 0, linetype="solid", color="black", size=10)
pl <- pl + geom_vline(xintercept = num_columns, linetype="solid", color="black", size=10)

# theming
pl <- pl + theme(panel.grid = element_blank(),
                           panel.background = element_rect(fill = "#000000"),
                           plot.background = element_rect(fill = "#000000", size = 0),
                           axis.text = element_blank(),
                           axis.ticks = element_blank(),
                           axis.title = element_blank()
                           )
# limits
pl  <- pl + xlim(-0.125*num_columns, 1.125*num_columns) + ylim(-2.4, 26.4)

So Here is the finished plot!

Finished Plot

Other Plots

Having looked at other heightmaps, you can see it works best with maps that are mostly islands (France just looks a tad too flat)

France

France Heightmap

Italy

Italy Heightmap

Japan

Japan Heightmap

New Zealand

New Zealand Heightmap