# Create_Fig6_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 6.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. Note this is output directly from FAVE vowel extraction software. path.to.file <- "~/Documents/DCB_se3_ag3_f_01_1-out.txt" # Read in the data input <- read.delim(path.to.file, header=TRUE) # Pull out the columns we want into a new data.frame, since the # FAVE output includes much more than we need. examp <- data.frame(Spkr = input$first_name, Vowel = input$vowel, Context = input$word, F1 = input$F1, F2 = input$F2, F3 = input$F3, F1gl = rep(NA, times=length(input$first_name)), F2gl = rep(NA, times=length(input$first_name)), F3gl = rep(NA, times=length(input$first_name)), Pre = input$pre_seg, Post = input$fol_seg) # Specify preceding and following contexts that we will care about pre.contexts <- c("B", "D", "G", "P", "T", "K", "S", "Z", "F", "V", "DH", "TH") fol.contexts <- c("B", "D", "G", "P", "T", "K", "S", "Z", "F", "V", "DH", "TH", "M", "N", "NG") vowels.of.int<- c("AE", "EH") # Now pull out just the vowels and contexts of interest vinterest <- droplevels(examp[examp$Vowel %in% vowels.of.int & examp$Pre %in% pre.contexts & examp$Post %in% fol.contexts,]) dim(vinterest) # 450 tokens # And the other vowels that we might want for contextualizing the positions # of the vowels of interest others <- droplevels(examp[examp$Vowel %in% c("AA", "AE", "AH", "AO", "AW", "AY", "EH", "EY", "IH", "IY"),]) # Relabel these using IPA characters; make sure the list of IPA characters lines up # with the original labels! others$Vowel <- as.factor(others$Vowel) levels(others$Vowel) levels(others$Vowel) <- c("ɑ", "æ", "ʌ", "ɔ", "aw", "ay", "ɛ", "e", "ɪ", "i") # Use vowels.R to compute means mn.others <- compute.means(others[,1:9]) # Can check the number of tokens for the different vowels and contexts: table(vinterest$Vowel, vinterest$Pre) table(vinterest$Vowel, vinterest$Post) # Set up plotting colors based on the number of Vowel+Following Environment pairings vinterest.clrs <- as.factor(paste(vinterest$Vowel, vinterest$Post, sep="")) clr.list <- rainbow(length(levels(vinterest.clrs))) levels(vinterest.clrs) <- clr.list vinterest.clrs <- as.character(vinterest.clrs) # Set the file name, uncomment the next lines and the very bottom to save the plot to a file # out.loc<-"~/Documents/DCB_se3_ag3_f_01_1-BOB-vowelplot.jpg" # jpeg(filename = paste(out.loc, ".jpg", sep=""), width = 6, height = 5, units = "in", res = 300, pointsize = 11, quality=100, bg = "white", type = "quartz", antialias="none") # Set up plotting space par(mai=c(0.8, 0.8, 0.4, 0.2), family="Helvetica") # Use vowelplot to first set up the plotting space, but just print in white at first vowelplot(vinterest, color="speakers", color.choice="white", leg=NA, title=paste("CORAAL speaker ", unique(vinterest$Spkr), sep="")) # Add a legend about the number of tokens for the vowel categories ltab <- table(vinterest$Vowel) names(ltab) <- c("/æ/", "/ɛ/") # If you change the vowels, be sure to update the labels here legend("bottomleft", paste(names(ltab), ltab, sep=" N = "), cex=0.8, bty="n") text(vinterest$F2, vinterest$F1, tolower(vinterest$Context), cex=0.7, col=vinterest.clrs) text(mn.others$F2, mn.others$F1, mn.others$Vowel, col="black", cex=2) # Return settings to their defaults par(defaults) # Uncomment to close the connection to the file, if writing to file # dev.off()