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

additional articles to journey through:

quicklinks
29 may 2012 | programming

The new-tab page on most browsers inefficiently uses screen real estate by giving each website a picture and large button. While useful for[...] tablets, it prevents addition of many websites and can't be organized into groups without increasing the number of clicks required. Also, often only one search site is accessible, with the rest found in a drop-down menu. To alleviate this, I created quicklinks. It uses javascript to create a row of categories (that you choose), which when hovered over show associated links. Further, there are several search bars readily avaliable, no extra clicking needed. Enjoy.

janelia journal club #2
06 july 2011 | science

The second presentation that Alyson and I gave during the Janelia Undergrad program, it was a brilliant paper that used Hidden Markov model[...]s to build a predictive algorithm that could tell you what chromatin states you were in.

social chair spring 2012
27 december 2011 | psk

My terms as social chair during Fall 2011 went quite well, but there were several things I was unsatisfied with. This presentation outlines[...] several different areas I would like to see improved.

global history of architecture
08 june 2013 | architecture

One of my favorite classes at MIT was 4.605 (Global History of Architecture), which explored various styles and themes found throughout dif[...]ferent buildings and other types of architecture from the beginning of civilization to the present. In the spirit of sharing my enthusiasm for the course i'll discuss some takeaways from, and have included a couple papers i wrote for, the class.

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