# Create_Fig3_3_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_3_data-RojTN.txt" # <- I.e. Edit this path # Read in the data input <- read.delim(path.to.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", "ʌ", "ɔ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) # Remove some of the less important categories, into a new data.frame roj <- droplevels(input[-which(input$IPA %in% c("el", "ɛl", "ɪl", "ʌl", "ʌN", "ɔl", "ɑl", "ɑɪl", "æl", "il")),]) # Use Vowels.R to generate means for the first speaker mroj <- compute.means(roj[,1:9]) mroj <- mroj[order(mroj$Vowel),] # Trim from the individual tokens cases with 2 or fewer tokens troj <- droplevels(roj[roj$IPA %in% mroj$Vowel[mroj$N > 2],]) # To save the plot to a file: Set the file name, uncomment the next lines and the very bottom # out.loc<-"~/Documents/RojTN-ThreeVowelPlots.jpg" # jpeg(filename = out.loc, width = 7.5, height = 2.5, units = "in", res = 300, pointsize = 12, quality=100, bg = "white", type = "quartz", antialias="none") # Set up plotting space par(mai=c(0.6, 0.6, 0.4, 0.2), family="Helvetica") par(mfrow=c(1,3)) # First version: # Use vowelplot to first set up the plotting space, but just print in white at first vowelplot(mroj, color="vowels", color.choice="white", label="vowels", leg=NA, title=paste("Roj vowels, v. 1", sep=""), xlim=c(2, -2), ylim=c(2, -2)) # Add ellipses using Vowels.R, using the trimmed troj data.frame add.spread.vowelplot(troj[order(troj$Vowel),1:9], ellipsis=TRUE, sd.mult=1, color="vowels", color.choice="darkgray") # Add the IPA labels using standard text() plotting function text(mroj[,5], mroj[,4], mroj[,2], col="black") # Second version: # Use vowelplot to plot the actual data in the mroj data.frame, so including glides vowelplot(mroj, color="vowels", color.choice="black", label="vowels", leg=NA, title=paste("Roj vowels, v. 2", sep=""), xlim=c(2, -2), ylim=c(2, -2)) # Third version: # Use vowelplot again just to set up the plotting space vowelplot(roj, color="vowels", color.choice="white", leg=NA, title=paste("Roj vowels, v. 3", sep=""), xlim=c(2, -2), ylim=c(2, -2)) # Now plot the individual tokens, just using their IPA labels text(roj[,5], roj[,4], roj[,2], col="black") # Return plotting settings to their defaults par(defaults) # If writing to file: Uncomment to close the connection to the file, # dev.off()