r functions: city skylines

Summary

An artistic rendering of Boston's skyline using R. Code and source data are included.

boston city skyline in polar coordinates

Been interested in using R (or other programming languages) to make artistic renderings of data—that is, representations that might not be as informative as well-made graphs, but are pleasing to look at purely for enjoyment. Took a stab at it earlier this year when representing usage statistics of a music group (club coat check member statistics) and for Cheyne-Stokes respiration. Wanted to make an artistic rendering of Boston's city skyline, again leaning on the use of polar coordinates as it is visually more interesting that using Cartesian. The code and csv file are included below.

boston building height csv files

download city_skylines_boston.R

R / S+
  1. # makes an artistic rendering of the boston city skyline
  2. # biafra ahanonu
  3. # updated: 2013.12.28
  4.  
  5. main <-function(inputFile,savePlot=1,saveFilename="city_skyline_boston.png",nrow=2,ncol=5,...){
  6.         # load in the data
  7.         dataFile = read.table(inputFile,sep=",",header=T);
  8.         # randomly group the buildings
  9.         dataFile$cat = round(runif(nrow(dataFile),1,nrow))
  10.         dataFile$scat = round(runif(nrow(dataFile),1,ncol))
  11.         # plot the data
  12.         cityPlot = ggplot(dataFile,aes(x=sample(c(nrow(dataFile))),y=stories,fill=building))+
  13.         scale_fill_hue()+
  14.         guides(fill=FALSE,group=FALSE)+
  15.         geom_bar(stat="identity",position="dodge")+
  16.         theme(
  17.                 axis.text.x = element_text(angle=90,hjust=1,vjust=.5,color="white"),
  18.                 panel.background=element_rect(fill="white",colour="white"),
  19.                 strip.text = element_blank(),
  20.                 strip.background = element_blank(),
  21.                 panel.grid = element_blank(),
  22.                 axis.text = element_blank(),
  23.                 axis.ticks = element_blank(),
  24.                 axis.title = element_blank()
  25.                 )+
  26.         facet_grid(cat~scat)+
  27.         coord_polar()
  28.  
  29.         # decide whether to save or display plot
  30.         if(savePlot==1){
  31.                 png(paste(saveFilename,sep=""),width=2400,height=2400,res=400,pointsize=1,antialias = "cleartype")
  32.                         print(cityPlot)
  33.                         # makeFootnote()
  34.                 dev.off()
  35.         }else{
  36.                 print(cityPlot)
  37.         }
  38. }
  39.  
  40. # run script
  41. main("buildings.height.boston.csv");

-biafra
bahanonu [at] alum.mit.edu

more articles to enjoy:

excess humanity
26 october 2013 | short story

The point was nearing when humanity needed to optimize the population. And so the question arose: how many humans do we need?[...]

quantized art
28 may 2012 | essay

Quantized art. The idea came about while reading how the music industry assembles top-liners, producers, artists, performers, etc. to [...]create top 40 hits. For example, there has been a recent trend in pop music to use 'drops', when the song builds to a crescendo and then a crazy, catchy bass line is released that causes everyone to dance. This has been perfected to the point where even an okay song can become popular because the producers know when to build, at what moment to intersperse catchy, meaningless lyrics and how to end the song on a high. I like the idea that art (as in paintings, drawings, etc.) can be dissected and quantified.

My first pass at developing an algorithm to break art down to its details and then use this knowledge to generate art that people would consider 'great'. We'll see how this evolves.

stanford bing concert hall: first impressions
15 december 2012 | stanford

Designed by architect Richard Olcott (Ennead Architects) and sound designer Dr. Yasuhisa T[...]oyota (Nagata Acoustics), the Bing Concert Hall is stunning. Robert Campbell (Fisher Dachs Associates) was on hand during the second sound check (along with Richard and Dr. Toyota) to discuss the philosophy behind the building, a bit of history, and where they hope it will be in the future. This post is my impressions of the place along with notes from their interview.

©2006-2025 | Site created & coded by Biafra Ahanonu | Updated 21 October 2024
biafra ahanonu