# Chapter 5: Making Controlled Comparisons
library(poliscidata) # Loads R companion package in session
# MULTIPLE LINE CHARTS
# First we need to tranform DV and update the gssD
# Retrieve level names of variable to graph.
levels(gss$grass)
# Create the indicator in the non-design dataset, multiplied times 100.
gss$grass.legal=as.numeric(gss$grass=="LEGAL")
gss$grass.legal=100*gss$grass.legal
# Run svydesign, updating gssD to include the new indicator.
gssD = svydesign(id=~1, data=gss, weights=~wtss)
# Multiple line chart, controlled comparison
iplotC(~grass.legal,~attend3+kids,gssD,grass.legal~kids+attend3,
xlab="Relgious attendance",
ylab="Percent favoring legalization",
main=list("Percentage Favoring Marijuana Legalization\n by Religious
Attendance and Kids",cex=1))
# the code below layers on top of line chart created above
legend("topright", #Locates the legend in the plotting area
legend=c("No","Yes"), #Labels the categories
lty=c(1,2), #Make sure the lin types match the legend labels
lwd=2, #Specifies the same line weight shown in the graph
title="Does R have kids?",
inset=0.1, #Specifies distance from the plot borders
bty="n") #Suppresses the box around the legend