FIND DATA: By Author | Journal | Sites   ANALYZE DATA: Help with R | SPSS | Stata | Excel   WHAT'S NEW? US Politics | Int'l Relations | Law & Courts
   FIND DATA: By Author | Journal | Sites   WHAT'S NEW? US Politics | IR | Law & Courts
Run R Code
About This Page
This page features live demonstrations of the R Statistics Program used for political science research.
  • To run example, click the Run button.
  • To copy example code, click the Copy button.


See More R Demos
Run R Code in Your Web Browser
#  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
Watch & Learn
thumbnail preview
â–º
i
Video tutorial & demo by Barry Edwards for R Companion to Political Analysis, 3rd Ed. (11:11).
 Sort and View Case-Level Information With the RCPA3's SortC Function
thumbnail preview
â–º
i
From Katie Ann Jager (4:27).
 Creating and Interpretting a Scatterplot Matrix
MORE VIDEOS: See Video Channels for more political science videos!
LEARN HOW: Watch Lecture Videos for Essentials of Political Analysis, Video Tutorials for R, Stata, SPSS, and Excel