[R-lang] vowel space ellipses (and IPA fonts)

Lngmyers lngmyers at ccu.edu.tw
Tue Jun 5 20:58:18 PDT 2007


Below I give some code I wrote for a student to plot vowel space 
ellipses. Five questions and one comment:

(1) Did I just reinvent the wheel? Does anybody already have better R 
code to do this?

(2) How do I get the axes to appear on the right and top, instead of 
left and bottom? I couldn't find parameters for doing this without 
drawing the whole thing piece by piece.

(3) When the user chooses to plot only the ellipses, the only way I 
could figure out how to get started was to plot the first vowel dots in 
white so they'd be invisible. Surely there's a better way to do this.

(4) Does anybody else have problems getting "else" to work right? I 
always end up having to use a series of disjunctive "if"s....

(5) Is there any way to get R to print IPA in graphs? I suspect that 
there might be, at least on some platforms, though I'm sure the process 
ain't pretty.

(6) R documentation sucks.

- James Myers
Graduate Institute of Linguistics
National Chung Cheng University

####################################################################
# To use this code, first create a data file as described below.   #
# Then open R, and use the menus to change the directory           #
#  to the folder where the data file is.                           #
# Then check the parameters below and change them to match your    #
#  data file and your goals (e.g. size of ovals, whether or not to #
#  to print dots or only ovals).                                   #
####################################################################

##################################################################
# Format of data file (text file with columns separated by tabs) #
##################################################################

#	Vowel	F1	F2.F1       (F2.F1 represents F2-F1)
#	a	864.8	913.5
#	...	...	...
#	e	690.41	1230.79
#	...	...	...

##################################
# Parameters that you can change #
##################################

  # Name of data file (must be inside quotation marks)

    fn = "vowdat.txt"

  # Names of vowels to be used in graph,
  # which must be inside quotation marks.
  #  The names must match those in the data file,
  #  so if you don't like them, change the data file.

    vn = c("a", "e", "i", "u", "oh", "schwa")

  # Approximate proportion of dots inside ovals
  #  (from 0 to 1: bigger = bigger ovals)

    prob = 0.90

  # TRUE = plot dots; FALSE = don't plot dots

    dots = TRUE

####################################
# Don't change the following code; #
#       just paste it into R       #
####################################

foundpack = F
tryload = try(library(car),T)
if (is.element("car",tryload)) {
  foundpack = T
}
if (!foundpack) {
  install.packages("car", dependencies = T)
  library(car)
}

vowdat = read.table(fn,T)
attach(vowdat)

numv = length(vn)

if (dots) {
  data.ellipse(F2.F1[Vowel==vn[1]], F1[Vowel==vn[1]], levels=prob,
   col="black", lty=1,
   ylim=c(max(F1),min(F1)),xlim=c(max(F2.F1),min(F2.F1)),
   xlab = "F2-F1 (Hz)", ylab = "F1 (Hz)")
}
if (!dots) {
  plot(F2.F1[Vowel==vn[1]], F1[Vowel==vn[1]],col="white",
   ylim=c(max(F1),min(F1)),xlim=c(max(F2.F1),min(F2.F1)),
   xlab = "F2-F1 (Hz)", ylab = "F1 (Hz)")
  data.ellipse(F2.F1[Vowel==vn[1]], F1[Vowel==vn[1]], levels=prob,
   col="black", lty=1, add=T, plot.points=F)
}

for (i in 2:numv) {
  if (dots) {
   data.ellipse(F2.F1[Vowel==vn[i]], F1[Vowel==vn[i]], levels=prob,
    add=T, col="black", lty=i, pch=i, center.pch=i)
  }
  if (!dots) {
   data.ellipse(F2.F1[Vowel==vn[i]], F1[Vowel==vn[i]], levels=prob,
    add=T, col="black", plot.points=F, lty=i, pch=i, center.pch=i)
  }
}

par(lwd=1)
par(lty=1)
legend("bottomleft",lwd=c(rep(2,numv)),lty=(1:numv),pch=(1:numv),
  legend=vn,bg="white")

detach(vowdat)






More information about the R-lang mailing list