# timePlots.R # # (c) Mary E. Beckman, Ohio State University # # Script for making a sample time plot for Data Analysis Problem # on "Pitch patterns and time plots" for Ling H286, Au 2007. # Begin by setting the working directory to the folder where # you have put the measurementsReport2.txt file that you made. # On Mary's computer, this directory is the report2sounds folder # in the Lx286 folder on the C: drive. The path name to the # folder on your computer is probably different, so you'll have # to edit this line to change that. setwd('C:/Lx286/report2sounds') # Read the data from the file into a data frame variable called # "pD" for "pitch data". pD=read.table("measurementsReport2.txt", header=TRUE) # Make a drawing window that is 1.5 inches wide by 2 inches high, # in which any text you draw will be 11 point. windows(width=1.5,height=2,pointsize=11) # NOTE: If you are using a Mac, let me know, and we can figure # out what the equivalent of "windows" is for MacOS X. # Tell R to use a "serif" font like Times New Roman, with no # outer margin, and an inner margin that is 2 lines wide on # the bottom and left side and 0.5 lines on the other two sides. par(family="serif", oma=c(0,0,0,0), mar=c(3,3,0.5,0.5), mgp=c(1.8,0.5,0)) # NOTE: If you are using a Mac, let me know, and we can figure # out what the equivalent of the family="serif" argument is for # the MacOS X version of R. # Get ready to plot the boy's Pitch timeplots, by setting # a "pitchRange" variable to two numbers for the floor and # ceiling values that you want -- here 100 and 400 Hz. pitchRange=c(100,400) # Also set the variable token to index the first row of the # table. token=1 # When you're getting ready to plot the second row, you would # set this to 2 instead, like this: # token=2 # Make a plot of the three pitch points for the first row of # the table, where circles are connected by lins. (That's # what the type="b" -- for type="both lines and points" does.) plot(1:3,pD[token,c("pitch1","pitch2","pitch3")], xlim=c(0,4), type="b", pch=19,ylim=pitchRange, xlab="",ylab="Pitch (Hz)", axes=F) # Add axis tick marks at 1, 2, 3 along the x-axis, and at ... axis(1, 1:3) # every 50 Hz along the range on the y-axis. axis(2, seq(pitchRange[1],pitchRange[2],50)) # Add dotted lines across at the tick marks, and draw a box. abline(h=seq(pitchRange[1],pitchRange[2],50),lty=2) box() # Put text identifying the speaker at the top left of the plot. mtext(as.character(pD[token,"speaker"]),line=-1,adj=0) # Put text identifying the word at the top right of the plot. mtext(as.character(pD[token,"word"]),line=-1,adj=1) # Make a name for the graph by pasting together the speaker # and the word, like this: plotName=paste(pD[token,"speaker"],pD[token,"word"],sep="_") # Save the plot to a jpeg file or some other file type. savePlot(plotName,type="jpg") # NOTE: If you are using a Mac, let me know, and we can figure # out what the equivalent save command is. ###################################################################### # Getting fancy ... # If you know about the concept of a for-loop and want to make # all of the time plots for one row in one jpg file, you could # also do this. # Make a wider window, and ... windows(width=6,height=2,pointsize=11) # Tell R to apply multiple graph functions in a row of 4. par(family="serif", oma=c(0,0,0,0), mar=c(3,3,0.5,0.5), mgp=c(1.8,0.5,0),mfrow=c(1,4)) # Set the pitch range. pitchRange=c(100,400) # Initialize the token variable to be the first row you want to # plot. token=1 plotName=as.character(pD[token,"speaker"]) # Loop through the four word tokens, doing what you did above. for (i in 1:4) { plot(1:3,pD[token,c("pitch1","pitch2","pitch3")], xlim=c(0,4), type="b", pch=19,ylim=pitchRange, xlab="",ylab="Pitch (Hz)", axes=F) axis(1, 1:3) axis(2, seq(pitchRange[1],pitchRange[2],50)) abline(h=seq(pitchRange[1],pitchRange[2],50),lty=2) box() mtext(as.character(pD[token,"speaker"]),line=-2,adj=0) mtext(as.character(pD[token,"word"]),line=-2,adj=1) # and incrementing the token variable before you go on. token=token+1 } savePlot(plotName,type="jpg")