# firstCode.R # # (c) 2007 by Mary E. Beckman for Linguistics H286 # # Script for making sample barchart of counts of word types of # different lengths in the Moe, Hopkins, and Rush (1982) list # of words used in conversations with first grade children. # Now set up a vector of numbers called "MHR" (for Moe, Hopkins, & # Rush, 1982) that has the counts for the word types in this list # that having different numbers of syllables. MHR=c(2671,2893,682,103,11,4) # Explanation: This line of code executes the function c() which # sets up a vector of numbers, which are the counts for 1-, 2-, 3-, # 4-, 5-, and 6-syllable words in the Moe, Hopkins, & Rush list. # Type MHR to see what the result is. You should see a list of # six numbers on your screen, like this: # # > MHR # [1] 2671 2893 682 103 11 4 # Assign the names "1", "2", "3", "4", "5", and "6" to the six # numbers in the vector MHR. names(MHR)=as.character(c(1:6)) # Explanation: The left-hand side of this assingment equation is # a function that lists the names of the object that is its # argument -- in this case, the names of the six numbers in the # vector MHR. The right-hand side specifies a vector of integers # from 1 to 6, treated as if the numbers were characters -- i.e., # letters or letter strings. The = operator assigns the vector # specified on the right to be the list of names for MHR. Type # "MHR" again to see the result. # Now make a barplot showing the relative sizes of these counts # for 1-, 2-, ..., and 6-syllable words. barplot(MHR) # Explanation: The barplot function draws a barplot, using the # named variable in the first argument as the data to be depicted. # Here we are plotting a simple vector of six quantities, so there # should be six bars, varying in height. The labels for the bars # underneath the x-axis should be what you specified for the names # of the numbers.