# Create_Fig5_1_Dec2020.R # R Script accompanying _Sociophonetics_ by Tyler Kendall & Valerie Fridland # Tyler Kendall & Valerie Fridland, 2020 (CC BY 4.0) # # This simple script recreates Figure 5.1 in the book. In addition to recreating # the figure, it is meant as an example for using Vowels.R for vowel plotting. # # Install the vowels.R library if you do not have it installed already # e.g. > install.packages("vowels", dependencies=T) library(vowels) # Set up graphical defaults, so it is easy to reset to the initial settings later par(bg='white') defaults<-par(no.readonly=TRUE) # Set the path to the input file, which you can obtain from the _Sociophonetics_ # website path.to.file <- "~/Documents/pb1952.csv" # <-- I.e.: You probably need to edit this # Read in the data pb52 <- read.csv(path.to.file) # Examine the data head(pb52) unique(pb52[, c("Vowel", "IPA")]) # Replace the original IPA labels with new IPA labels; make sure these line up pb52$IPA <- as.factor(pb52$IPA) levels(pb52$IPA) levels(pb52$IPA) <- c("æ", "ɑ", "ɔ", "ɛ", "ɝ", "ʊ", "ɪ", "ʌ", "i", "u") # Set up a new data.frame for Vowels.R pb.vwls <- data.frame(Spkr = as.character(pb52$Speaker), Vowel = as.character(pb52$IPA), Context = as.character(pb52$Vowel), F1 = pb52$F1, F2 = pb52$F2, F3 = pb52$F3) # Even though we don't have glides, the functions in Vowels.R expect glide columns pb.vwls$F1gl <- NA pb.vwls$F2gl <- NA pb.vwls$F3gl <- NA # Can examine more, e.g. summary(pb.vwls) # Set up some colors for plotting vcls <- as.factor(pb.vwls$Vowel) levels(vcls) <- rainbow(length(levels(vcls))) vcls <- as.character(vcls) # Set up plotting space par(mai=c(0.6, 0.6, 0.6, 0.2), family="Helvetica") # Use vowelplot to first set up the plotting space, but just print in white at first vowelplot(pb.vwls, color="vowels", color.choice="white", leg=NA, title="Peterson & Barney Vowel data (non-norm'd)") # Now, using regular text() function to add text to a plot, add the IPA characters text(pb.vwls$F2, pb.vwls$F1, pb.vwls$Vowel, col=vcls, cex=0.7) # Return settings to their defaults par(defaults) # Normalize the vowels, using Lobanov normalization method pb.nvwls <- norm.lobanov(pb.vwls) # Plot again, this time the normalized vowels par(mai=c(0.6, 0.6, 0.6, 0.2), family="Helvetica") vowelplot(pb.nvwls, color="vowels", color.choice="white", leg=NA, title="Peterson & Barney data (Lobanov norm'd)") text(pb.nvwls$`F*2`, pb.nvwls$`F*1`, pb.nvwls$Vowel, col=vcls, cex=0.7) par(defaults) # Plot these as two side-by-side panels par(mfrow=c(1,2)) par(mai=c(0.4, 0.4, 0.2, 0.1), family="Helvetica") vowelplot(pb.vwls, color="vowels", color.choice="white", leg=NA, title="Peterson & Barney Vowel data") text(pb.vwls$F2, pb.vwls$F1, pb.vwls$Vowel, col=vcls, cex=0.6) legend("bottomleft", "Raw (Non-normalized)", bty="n") vowelplot(pb.nvwls, color="vowels", color.choice="white", leg=NA, title=" ") text(pb.nvwls$`F*2`, pb.nvwls$`F*1`, pb.nvwls$Vowel, col=vcls, cex=0.6) legend("bottomleft", "Lobanov normalized", bty="n") par(defaults)