# 11.6 Visualizing missing data =========================================== 11.6
myDF = data.frame(cbind( # Create some data w/missing variables
c(1, 3, 4, NA, 2, 5, NA, 7, 9, 3, 2, 5),
c(7, 8, 2, 4, 3, 6, 9, 1, 0, 4, 2, NA),
c(6, NA, 3, NA, 4, 6, 1, 9, NA, 2, NA, 8),
c(5, 3, 2, NA, 2, 1, 8, 6, 7, 4, 7, 9)))
rownames(myDF) = paste( # Paste together observation labels
rep("Subject", 12), # by concatenating "subject"
c(seq(1:12))) # with numbers 1-12
# Ceate a vector with the number of missing values for each observation
missobs = apply(myDF, 1, # Create new variable w/num missing
function(x) sum(is.na(x))) # for each observation
missobs = sort(missobs, decreasing=T) # Sort from most to least missing
png(filename = "illustrations/fig-11-1-missing-values.png",
units = "in", # Set measurements in inches
res = 1200, # Set resolution at 1200dpi
width = 6, # Width at 6 inches
height = 4) # Height at 4 inches
par(mai = c(1, 1, .25, .25)) # Set margins - no title
dotchart(missobs, # Create a plot of missingness
las = 1, # Rotate the y labels by 90 degrees
xlim = c(0, length(myDF[1,])), # Set range of x axis to num of vars
xlab = "Number of Missing Observations")
dev.off() # Output png
Figure 11-1: A Basic Dot Chart
Portfolio Categories: All Graphics and SGR Book Graphics.