Get Data

Data may be imported from a local file or downloaded from the web. For this example we will use a CSV file downloaded from the web and data entered by hand.

  htwt = read.csv("http://facweb1.redlands.edu/fac/jim_bentley/downloads/math111/htwt.csv")
  htwt$Group = factor(htwt$Group, labels=c("Male","Female"))
  head(htwt)
##   Height Weight  Group
## 1     64    159   Male
## 2     63    155 Female
## 3     67    157 Female
## 4     60    125   Male
## 5     52    103 Female
## 6     58    122 Female

For now, We will focus on the weight (Weight) data in the htwt dataframe.

 names(htwt)
## [1] "Height" "Weight" "Group"
 htwt$Weight
##  [1] 159 155 157 125 103 122 101  82 228 199 195 110 191 151 119 119 112  87 190
## [20]  87

We can create a quick dotplot/stripchart using the base package.

  stripchart(htwt$Weight)

  stripchart(htwt$Weight ~ htwt$Group)

  stripchart(Weight ~ Group, data=htwt)

The lattice package provides a little more flexibility in creating dotplots. In particular, considering additional variables through the use of lattices (latti?) is sometimes useful in making comparisons.

  # Use the lattice library.  cex is the character size multiplier    
  # Using pch=1 chooses open circles which better show overlapped data. 
  p_load(lattice)
  dotplot(~Weight, data=htwt, cex=1.25, pch=1)

  # Lattice requires that the grouping variable be an integer and not factor variable
  dotplot(as.integer(Group) ~ Weight, data=htwt, cex=1.25, pch=1, ylab="Group")

  dotplot(~Weight, group=Group, data=htwt, pch=htwt$Group)

  dotplot(~Weight|Group, data=htwt, layout=c(1,2))