##### ##### ### Creating Figure 4 ##### ##### library(lattice) ##### ##### ### Requires data file: ### "import.txt" ##### ##### import.2004 <- read.table(file.choose(), header = T) var.labels <- c("Govt. spending", "Defense spending", "Govt. health insurance", "Guaranteed jobs", "Aid to Blacks", "Jobs vs. environment", "Gun control", "Womens role", "Diplomacy vs. military", "Abortion") sample.means <- mean(import.2004, na.rm = T) std.devs <- sd(import.2004, na.rm = T) sample.ns <- apply(!is.na(import.2004), 2, sum) std.errs <- std.devs / (sample.ns ^ .5) lower <- sample.means + (std.errs * qt(.025, (sample.ns - 1))) upper <- sample.means + (std.errs * qt(.975, (sample.ns - 1))) new.data <- data.frame(var.labels, sample.means, lower, upper) new.data$var.labels <- reorder(new.data$var.labels, new.data$sample.means) dotplot(var.labels ~ sample.means, data = new.data, aspect = 1.5, xlim = c(3.3, 4.3), xlab = "Mean importance rating", panel = function (x, y) { panel.xyplot(x, y, pch = 16, col = "black") panel.segments(new.data$lower, as.numeric(y), new.data$upper, as.numeric(y), lty = 1, col = "black")} )