# Create_Fig3_2_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 3.2 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/Fig3_2_data-KristenNY+LindseyNV.txt" # Read in the data input <- read.delim(path.to.file, header=TRUE) # Add a new column with the IPA characters for the VowelCat # Note: This requires that the list of IPA characters matches the VowelCats, so # you will want to check this if you make any changes to the file input$IPA <- as.factor(input$VowelCat) levels(input$IPA) # Check the levels before replacing with a list of IPA characters levels(input$IPA) <- c("æ", "æ", "e", "el", "e", "æN", "æ", "i", "i", "ɛ", "ɛ", "ɪ", "ɑɪD", "ɪ", "ɑɪT", "o", "u", "ɑ", "ɔ", "ɑw", "ol", "ʌN", "ʌ", "ɔl", "ɑl", "ɑɪl", "æl", "ʊ", "ul") # Reorder the columns so that the new IPA column is in 2nd position input <- input[, c(1, 14, 3:9, 2, 10:13)] # You can check this: head(input) # Now pull out the two speakers into new data.frames - this allows us to modify # those further for plotting without changing the main data.frame anymore. sp1 <- input[input$Speaker=="Kristen (NY)", ] sp2 <- input[input$Speaker=="Lindsey (NV)", ] # Remove some of the less important categories sp1 <- droplevels(sp1[-which(sp1$IPA %in% c("el", "ɛl", "ɪl", "ʌl", "ʌN", "ɔl", "ɑl", "ɑɪl", "æl", "il")),]) sp2 <- droplevels(sp2[-which(sp2$IPA %in% c("el", "ɛl", "ɪl", "ʌl", "ʌN", "ɔl", "ɑl", "ɑɪl", "æl", "il")),]) # Use Vowels.R to generate means for the first speaker msp1 <- compute.means(sp1[,1:9]) # Trim from the individual tokens cases with 2 or fewer tokens sp1 <- droplevels(sp1[sp1$IPA %in% msp1$Vowel[msp1$N > 2],]) # Repeat for the second speaker msp2 <- compute.means(sp2[,1:9]) sp2 <- droplevels(sp2[sp2$IPA %in% msp2$Vowel[msp2$N > 2],]) # Set up plotting space par(mai=c(0.6, 0.6, 0.2, 0.2), family="Helvetica") par(mfrow=c(1,2)) # Use vowelplot to first set up the plotting space, but just print in white at first vowelplot(msp1, color="vowels", color.choice="white", title=unique(sp1$Speaker), label="vowels", leg=NA, xlim=c(3000, 500), ylim=c(1000, 300)) # Now add gray ellipses add.spread.vowelplot(sp1[order(sp1$Vowel),1:9], ellipsis=TRUE, sd.mult=1, color="vowels", color.choice="darkgray") # Now, using regular text() function to add text to a plot, add the IPA characters text(msp1[,5], msp1[,4], msp1[,2], col="black") # Repeat for speaker 2 vowelplot(msp2, color="vowels", color.choice="white", title=unique(sp2$Speaker), label="vowels", leg=NA, xlim=c(3000, 500), ylim=c(1000, 300)) add.spread.vowelplot(sp2[order(sp2$Vowel),1:9], ellipsis=TRUE, sd.mult=1, color="vowels", color.choice="darkgray") text(msp2[,5], msp2[,4], msp2[,2], col="black") # Return settings to their defaults par(defaults)