#12.10. R code #In this section we will show you how to recreate the bar plots for the distributions of θ and ð pronunciations in Figure 12.3. That is, the following lines of code review how to make a simple bar plot for each of these distributions. They’re not quite as fancy as the bar plots in the original figure, but show the same essential information. #First, let’s make the panel of the figure showing the distribution of pronunciations of θ that was our observed data. Start by making a vector (a one-dimensional matrix) called theta containing the numbers you want to plot. theta <- c(27,3,5) #Then specify a vector of names for these numbers. names(theta) <- c("dict.","repl.","del.") #Finally, create a bar plot. This command means: Create a barplot of the vector you called theta. The xlab and ylab commands let you add a label for the x- and y-axes. Finally, the ylim command specifies the limits of the y-axis. barplot(theta, xlab="theta pronunciations", ylab="number of pronunciations", ylim=c(0,29)) #Here is the analogous sequence of commands for the right-hand panel of the figure. eth <- c(43,28,37) names(eth) <- names(theta) barplot(eth,xlab="eth pronunciations", ylab="number of pronunciations",ylim=c(0,89)) #Note that in the second line, we can use the names() function on both sides of the assignment operator, because we already specified the vector of names for the theta variable. Notice also that we chose a different set of numbers for the ylim argument because we want a y-axis scale that is appropriate for the different total numbers of the theta and eth variables. That is, we want the y-axis to be appropriate for comparing the proportions for each type. This let’s us compare the distribution of the original model counts on the left with the distribution of the predicted counts on the right. #Finally, overlay another bar plot showing the expected counts. barplot(c(83,9,15), density=25, add=TRUE, col="black") #We made this bar plot an overlay by specifying the value TRUE for add argument. Also, note that we’ve specified a value of 25 for the density argument. That argument makes fill pattern be a set of diagonal shading lines spaced just far enough to have 25 of them per inch of the graph. #We could also have got more precise values for the expected count, like this: expected <- sum(eth)*(theta/sum(theta)) barplot(expected, density=25, add=TRUE, col="black")