## setwd('R/Fun/BeatleSongs') ## rm(list=ls()) Sys.setlocale("LC_TIME", "us") source('http://biostat.mc.vanderbilt.edu/twiki/pub/Main/TatsukiRcode/TatsukiRcodeTextBox.r') ## Color and Font Sizes ## For poster (width = 28 inches / height = 21 inches) size1 <- 2.5 size2 <- 2.0 size3 <- 1.0 size4 <- 1.0 bkgrc1 <- '#fcfbfd'#'#f7f4f9'#'#fff7ec' #colors()[18] #colors()[138] bkgrc2 <- grey(.97) bkgrc3 <- colors()[626] linec <- grey(.92) textc1 <- grey(.25) textc2 <- grey(.45) pointc <- c('black','red','blue','purple') fs <- 1.3 grey1 <- grey(.8) dx <- read.csv('http://biostat.mc.vanderbilt.edu/twiki/pub/Main/TatsukiRcode/Beatlesongs072108.csv') dx$Album <- as.character(dx$Album) ## Change the info on 'Bad Boy' to that of UK release. dx[dx$Song=='Bad Boy',1] <- 'A Collection of Beatles Oldies' rd1 <- as.character(dx$Release.Date) rd2 <- matrix(unlist(strsplit(rd1,'/')),ncol=3,byrow=T) rdy <- paste('19',rd2[,3],sep='') rdx <- paste(rdy,rd2[,1],rd2[,2],sep='/') dx$Release.Date <- as.Date(rdx) dx[dx$Song=='Bad Boy',2] <- as.Date('1966-12-10') dx <- dx[order(dx$Release.Date),] row.names(dx) <- 1:nrow(dx) dx$Album <- factor( alb.t <- as.character(dx$Album), levels=unique(alb.t) ) ## Correction to the dataset dx$Credits[dx$Song=='Maggie Mae'] <- 'lmhs' dx$Seconds[dx$Song=='Please Please Me'] <- 4 dx$Seconds[dx$Song=='Yellow Submarine'] <- 38 dx$Seconds[dx$Song=="A Hard Day's Night"] <- 32 dx$Seconds[dx$Song=='Ask Me Why'] <- 24 dx$Seconds[dx$Song=="Can't Buy Me Love"] <- 11 dx$Seconds[dx$Song=='Eleanor Rigby'] <- 7 dx$Seconds[dx$Song=='I am the Walrus'] <- 34 dx$Seconds[dx$Song=='P.S. I Love You'] <- 5 dx$Seconds[dx$Song=='Things We Said Today'] <- 38 dx$Seconds[dx$Song=='Ticket to Ride'] <- 10 dx$Seconds[dx$Song=="You Can't Do That"] <- 38 dx$Length <- dx$Minutes * 60 + dx$Seconds dx$Song <- as.character(dx$Song) dx$Credits <- as.character(dx$Credits) dx$Credits[dx$Credits==''] <- 'lm' dx$Credits[dx$Credits %in% c('lmhs','lms','s')] <- 'o' dx$Credits <- factor(dx$Credits,levels=c('lm','h','c','o'), labels=c('Lennon-McCartney','Harrison','Cover','Other')) dx$id <- 1:nrow(dx) ; row.names(dx) <- dx$id ## Songs in a Compliation album are included only if they are unavailable otherwise. ## "I am the Walrus" in Magical Mystery Tour will be deleted. d <- dx[!(dx$Song=='I am the Walrus' & dx$Album=='Magical Mystery Tour'),] x <- d$Release.Date ; y <- d$Length x.jit <- 4 neighbor <- 2 ## jitter only if the release date and length are identical ## rdl <- paste(d$Release.Date, d$Length, sep=',') rdl.dup <- rdl[duplicated(rdl)] this <- rep(0,length(rdl.dup)) for(i in 1:length(rdl.dup)){ this[i] <- sum(rdl==rdl.dup[i]) } d$pos2 <- rep(0,nrow(d)) for(i in 1:length(rdl.dup)){ pos <- which(rdl==rdl.dup[i]) if(length(pos)==2){ d$pos2[pos] <- c(-x.jit,x.jit) } if(length(pos)==3){ d$pos2[pos] <- c(-x.jit,0,x.jit) } } group <- unique(x) group.size <- length(group) ## Album Release Date album.titles <- levels(d$Album)[which(table(d$Album)>5)] album.titles <- album.titles[album.titles != 'Magical Mystery Tour'] album.rd <- unique( d$Release.Date[d$Album %in% album.titles] ) ep.titles <- c('Long Tall Sally','Magical Mystery Tour') ep.rd <- unique( d$Release.Date[d$Album %in% ep.titles] ) xrange <- range(d$Release.Date)+c(-60,60) yrange <- range(d$Length)*c(0,1.05) yrange[1] <- -20 xrange[1] <- as.Date('1962-05-01') ########## ## PLOT ## ########## pdf('BeatlesongsPoster.pdf', width=28, height=21) ## plot parameters par(family='serif') par(mar=c(7.5,5,7.5,5)+.1) par(adj=0.5) par(bg=bkgrc2) ## Plot plot(d$Release.Date,d$Length, type='n',las=1,bty='n',xaxt='n',yaxt='n', xlab='',ylab='', xlim=xrange,ylim=yrange,xaxs='i',yaxs='i') rect(xrange[1],0,xrange[2],yrange[2],col=bkgrc1,border=bkgrc1) axis(side=2,at=60*(0:3),label=0:3,tick=F,las=1,line=-.8, cex.axis=size3) axis(side=4,at=60*(0:8),label=0:8,tick=F,las=1,line=-.8, cex.axis=size3) ard <- format(album.rd, '%Y/%m/%d') ## grid abline(h=60*(0:8), col=linec, lty=1) ylines <- as.Date(paste(1963:1971, '-1-1', sep='')) for(i in ylines){ lines(rep(i,2),c(0,600), col=linec, lty=1) } ## Album Summary mi <- as.vector(sapply(split(d,d$Album), function(x) min(x$Length) )) ma <- as.vector(sapply(split(d,d$Album), function(x) max(x$Length) )) hm.rd <- length(mi) all.rd <- d$Release.Date[!duplicated(d$Album)] ## label year and arrow text(ylines,rep(2,9), substr(ylines,1,4), col=textc2, cex=size3, pos=4, offset=0.08) text(ylines+28,rep(2.5,9), expression(''%->%''), col=textc2,pos=4,cex=size3, offset=0.4) text(as.Date('1962-5-20'),2,'1962', col=textc2, cex=size3, pos=4, offset=0.08) text(as.Date('1962-5-20')+28,2.5, expression(''%->%''), col=textc2,pos=4,cex=size3, offset=0.4) ## label album release date (also the first single) shift <- which(album.titles=='Yellow Submarine') a.rd.md <- paste( format(album.rd, '%b'), as.numeric(format(album.rd, '%d'))) text(album.rd[-shift], -4, a.rd.md[-shift], xpd=T, adj=0.5, cex=size3, col=textc2) text(album.rd[ shift]+10, -4, a.rd.md[ shift], xpd=T, adj=0.5, cex=size3, col=textc2) first.single.date <- d$Release.Date[d$Album=='z01'][1] ; fsd <- paste( format(first.single.date,'%b'), as.numeric(format(first.single.date, '%d'))) text(first.single.date, -4, fsd, xpd=T, adj=0.5, cex=size3, col=textc2) ## album name and the triangle above text(album.rd[-shift], rep(-13.0,length(album.rd)-1),album.titles[-shift], cex=size3, xpd=T, srt=30, adj=1) text(album.rd[ shift], -13, album.titles[ shift], cex=size3, xpd=T, srt=30, adj=1) points(album.rd, rep(-09,length(album.rd)), cex=size3, xpd=T, pch=17) ## Vertical Lines connecting shortest and longest songs within album / single. for(i in 1:hm.rd){ lines(rep(all.rd[i],2),c(mi[i],ma[i]), col=grey1,lwd=1.5, lend=0) } ## R/pdf does something funny. Right indent (pos=2) doesn't work properly when there is a letter 'Y' in the word. ## An excetra space is added at the end of the word which includes the letter 'Y'. how.many.Y <- sapply(strsplit(d$Song,''), function(x) sum(x=='Y') ) ex.space <- rep('',length(d$Song)) for( i in 1:length(d$Song)){ex.space[i] <- paste(rep(' ',how.many.Y[i]),sep='',collapse='')} d$Song <- paste(d$Song, ex.space, sep='') ## Songs to be named... name.songs <- d[d$Length >= 260 | d$Length <= 100,] name.songs <- subset(name.songs, !(Album=='Magical Mystery Tour' & Song=='I am the Walrus')) name.songs <- subset(name.songs, !(Album=='z21' & Song=='Come Together')) named1 <- d[substr(d$Song,1,5) %in% c('Straw', 'You W'),] named2 <- d[d$Album=='z01',] named3 <- d[d$Song=='Bad Boy' | d$Song=='Get Back' | d$Song=='Let It Be',] name.songs <- rbind(name.songs, named1, named2, named3) ## Writing the song names for(i in 1:nrow(name.songs)){ text.with.bg(name.songs$Release.Date[i]-9, name.songs$Length[i], name.songs$Song[i], bkgr=bkgrc1, x.adj=1, width.adj=.3, height.adj=.2, cex=size3, col=textc1) } ## Song names that require an arrow (manually written) arrows(as.Date('1964-06-09'),160, x1<-as.Date('1964-04-09'),203, length=.05, angle=30,code=1,lty=1, lwd=0.2, col=grey1) text.with.bg(x1,205,'Long Tall Sally (EP)', bkgr=bkgrc1, x.adj=.5, width.adj=.3, height.adj=.2, cex=size3, font=3, col=textc1) arrows(as.Date('1967-11-28'),158, x1<-as.Date('1967-09-28'),110, length=.05, angle=30,code=1,lty=1, lwd=0.2, col=grey1) text.with.bg(x1,108, 'Magical Mystery Tour (EP)', bkgr=bkgrc1,x.adj=.5, width.adj=.3, height.adj=.2, cex=size3, font=3, col=textc1) arrows(x0<-as.Date('1966-07-26'),119.5, x1<-as.Date('1966-05-05'),110, length=.05, angle=30, code=1,lty=1,lwd=0.2,col=grey1) text.with.bg(x1,110, 'And Your Bird Can Sing', bkgr=bkgrc1,x.adj=1,width.adj=.3, height.adj=.2, cex=size3, font=1, col=textc1) arrows(x0+12,119,x0-20,100, length=.05, angle=30, code=1,lty=1,lwd=0.2,col=grey1) text.with.bg(x0-20,100, 'For No One', bkgr=bkgrc1, x.adj=.5, width.adj=.3, height.adj=.2, cex=size3, col=textc1) ## text ## default <- list(family='serif', font=1, col=1, cex=fs) txt1 <- c( 'Introduction
The Beatles released 211 songs, give or take, from their debut single Love Me Do (released October 5, 1962)', 'to their final studio album Let It Be (May 8, 1970), in the space of just under eight years.', 'This plot shows length versus release date of each of their songs. All release dates are for the UK market.', '

Data and Notation
The closed circles indicate songs included on their 12 studio albums, the titles and release dates of which appear in the abscissa.', 'The Beatles also released 44 songs as singles, shown here with open circles.', 'Sixteen songs were released twice each, both as a single and as part of an album; all of these pairs are identical in both versions except for', 'GetBack and LetItBe. YellowSubmarine was released three times: first as a single and on Revolver', '(both on August 5, 1966), and later on Yellow Submarine (January 17, 1969).', '

The studio albums and singles encompass all but ten of their songs. Two of their 13 extended play albums (EPs),', 'Long Tall Sally and Magical Mystery Tour, consist of songs that were never released elsewhere.', 'A total of nine songs from these two EPs are also shown in the plot as open circles.', 'Magical Mystery Tour>_ includes I am the Walrus, which is not shown in the plot because it was previously released as a single.', 'One song was never a part of any studio album, single, or EP: Bad Boy was released on December 10, 1966, on a compilation album,', 'A Collection of Beatles Oldies , with 15 other songs, all of which were previously released.', 'This track was available in the US market more than a year earlier, on June 14, 1965, when it was included in Beatles VI.' ) txt2 <- c( '

The black points are songs credited to Lennon>-McCartney,', 'red indicates Harrison as songwriter, the purple originates with other combinations of the Beatles,', 'and the blue points are cover songs.', '

To prevent songs with exactly the same length and release date from appearing on top of each other, data points are jittered horizontally', 'when necessary, by a small amount equivalent to four days. For example, both And Your Bird Can Sing and ForNoOne', 'from Revolver are two minutes and one second long.', '

Some Observations
The vast majority of songs in the early phase of their career (up to Revolver', ') are between two and three minutes in length, perhaps reflecting expectations for radio play at the time.', 'The inclusion of a relatively large number of cover songs during this period may also have been intended to attract a wider audience.', 'All 23 of their cover songs come from this early phase.', '

The end of this early phase is marked by their final concert, which took place on August 29, 1966,', '24 days after the release of Revolver.', 'After this concert, the Beatles started to spend much more time in the studio creating less traditional and', 'radio>-friendly songs.', 'Songs lasting longer than three minutes became commonplace, though they also released many short songs during this same time period.', 'Furthermore, Harrison\'s contribution was much more prominent during this later phase.' ) txt3 <- c( '

Acknowledgement
Data were gathered from wikipedia.org', 'and modified based on the actual length of songs on CDs,', 'and R version 2.7.0 was used to create the plot.', 'RafeDonahue made a number of suggestions that greatly improved the plot.', 'Thanks also go to ShaunHaskins and LynneBerry who edited the discussion of the plot.', '

The data and R codes are available upon request via email to the author', '(>tatsuki.koyama@vanderbilt.edu).' ) xpad <- as.Date('1962-6-11')-xrange[1] ww1 <- text.box(tex=txt1, x=c(as.Date('1962-6-11'),as.Date('1967-8-01')), y=507.00, x.padding=c(100,20), y.padding=c(55,2), vertical.stretch=1.8, paragraph.break=1.5, bkgr.col=bkgrc1, justify=T, slide.quote=T, after.=1.75) ny1 <- get.next.y(ww1) ww2 <- text.box(tex=txt2, x=c(as.Date('1962-6-11'),as.Date('1966-05-15')), y=ny1[2], x.padding=c(100,20), y.padding=c(5,5), vertical.stretch=1.8, paragraph.break=1.5, bkgr.col=bkgrc1, justify=T, slide.quote=T, after.=1.75) ny2 <- get.next.y(ww2) ww3 <- text.box(tex=txt3, x=c(as.Date('1962-6-11'),as.Date('1965-11-01')), y=ny2[2], x.padding=c(100,20), y.padding=c(5,3), vertical.stretch=1.8, paragraph.break=1.5, bkgr.col=bkgrc1, justify=T, slide.quote=T, after.=1.75) ## Title and Name apos <- strsplit(sQuote(NULL),'')[[1]][2] suppressWarnings( title(main=paste('Lengths of the Beatles',apos, ' Songs',sep=''), cex.main=size1, font.main=2, line=0.4, adj=0) ) title(main="Tatsuki Koyama, PhD", line=2.2, cex.main=size2*1.2, font.main=2, adj=1) title(main="Department of Biostatistics, Vanderbilt University",line=0.4, cex.main=size2, font.main=2, adj=1) title(ylab='Song Length (Minutes)', cex.lab=size2*0.8, mgp=c(1,0,0), font.lab=1, adj=.3) ## Plotting the points finally! singles <- !(d$Album %in% album.titles) ; pch.sa <- ifelse(singles, 21,19) points(d$Release.Date+d$pos2, d$Length, pch=pch.sa, cex=size4,col=pointc[c(d$Credits)]) dev.off()