1.11 Graphing histograms and box plots


The hist()function draws a histogram of an object representing a variable vector. For a histogram of age of first walking from our example (I copied and pasted the histogram from the R window into this document):

> hist(agewalk)

By default, R uses the variable name (agewalk) in the title and x-axis label for the histogram. The default title can be over-written using the 'main=paste( )' option, and the x-axis label can be overwritten using the 'xlab=' option. For example,

> hist(Age_walk,main=paste("Histogram of Age at Walking"),xlab="Age at Walking")

For boxplots comparing the distributions of age of first walking for the two study groups:

> boxplot(agewalk ~ group)

Box plots in R give the minimum, 25th percentile, median, 75th percentile, and maximum of a distribution; observations flagged as outliers (either below Q1-1.5*IQR or above Q3+1.5*IQR) are shown as circles (no observations are flagged as outliers in the above box plot). So, for study group 1, the youngest age at walking was 9 months, the median was about 10 months, and the oldest age at walking was 13 months.

Labels can be added to the x-axis and y-axis using the 'xlab=' and 'ylab=' options:

> boxplot(agewalk ~ group,xlab="Study Group", ylab="Age in Months")