# NOT RUN {
data(BushApproval)
attach(BushApproval)
## Plot data with confidence intervals. Each poll gets different line type
## no points at first
plot(strptime(date,"%m/%d/%y"),approval,type="n",
ylab = "Approval Rating",xlab="Date",
ylim=c(30,100)
)
## plot line for CI. Margin or error about 3
## matlines has trouble with dates from strptime()
colors = rainbow(6)
for(i in 1:nrow(BushApproval)) {
lines(rep(strptime(date[i],"%m/%d/%y"),2),
c(approval[i]-3,approval[i]+3),
lty=as.numeric(who[i]),
col=colors[as.numeric(who[i])]
)
}
## plot points
points(strptime(date,"%m/%d/%y"),approval,pch=as.numeric(who))
## add legend
legend((2003-1970)*365*24*60*60,90,legend=as.character(levels(who)),lty=1:6,col=1:6)
detach(BushApproval)
# }
Run the code above in your browser using DataLab