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:

bash scripting: randomly rename files
13 june 2013 | programming

Small script to enable quick randomization of files in a directory and conversion back to original names later. Original inspiration was a [...]way to blind data analysis, e.g. if studying images from an experiment and don't want to be biased by the conditions applied.

from the archives: declaration of independence, internet edition
11 july 2013 | america

A revised Declaration of Independence I did awhile ago (i.e. high school) for a writing class. It is slightly a mockery of the style of wri[...]ting sometimes used back then, e.g. finding unnecessarily complicated ways of saying a simple concept; long, ponderous sentences; and an abuse of the Capital.

state of sbsa: a review of 2017 and thoughts on future directions
04 june 2017 | sbsa

I spent the past year leading the Stanford Biosciences Student Association (SBSA) as President. This post consist of the letter to the comm[...]unity I sent out at the end of my term giving some highlights of the past year, those who have helped out, and thoughts on future directions.

comment system!
05 august 2012 | website

Wanted to add the ability for people to comment on this website, but delayed adding the feature until I could write the code myself. There [...]are many pre-built PHP solutions on the market (like commentator), but the original purpose of this site was to allow me to learn how to build a website from scratch. So I've implemented the comment system using about a hundred lines of code to access the MySQL database, verify inputs and display all the comments for a particular article.

©2006-2024 | Site created & coded by Biafra Ahanonu | Updated 17 April 2024
biafra ahanonu