-
Notifications
You must be signed in to change notification settings - Fork 1
/
Prosport.R
95 lines (75 loc) · 2.1 KB
/
Prosport.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require(foreign)
# setwd("")
# Import the SPSS data using read.spss:
prosport<-data.frame(read.spss("prosport.sav", use.value.labels=TRUE))
# XY plot of Pro athletes versus house districts:
png(filename="prosportscatterplot.png",
width=6, height=5, units="in",
pointsize=10,
bg="white",
res=300,
type="quartz"
)
plot(prosport$HOUSE,prosport$PROS,
main="Pro Athletes and State House District Counts",
xlab="US House Districts in State",
ylab="Pro Athletes from State",
pch=21,
col="black",
bg="red"
)
dev.off()
# Pro Sports scatterplot with regression line:
png(filename="prosportscatterplotregress.png",
width=6, height=5, units="in",
pointsize=10,
bg="white",
res=300,
type="quartz"
)
plot(prosport$HOUSE,prosport$PROS,
main="Pro Athletes and State House District Counts",
xlab="US House Districts in State",
ylab="Pro Athletes from State",
pch=21,
col="black",
bg="red"
)
# Fitted regression line:
regline<-lm(prosport$PROS~prosport$HOUSE)
abline(regline, col="blue")
# All labels:
# text(prosport$HOUSE,prosport$PRO, prosport$ABBREV, cex=1, pos=4, col="black")
# Subset of labels:
proframe<-data.frame(prosport)
labelstates<-subset(proframe,
PROS==310 | PROS==318 | PROS == 164 | PROS == 269 )
# Four points (excluding California, which *should be* obvious)
text(labelstates$HOUSE,
labelstates$PROS,
labelstates$ABBREV,
cex=1,
pos=4,
col="black"
)
dev.off()
# Just the Southern states:
southern<-subset(proframe, SOUTH==1)
# text(southern$HOUSE,southern$PROS, southern$ABBREV, cex=1, pos=4, col="brown")
# Histogram of state US House districts count:
png(filename="HouseDistrictsHistogram.png",
width=5, height=5, units="in",
pointsize=12,
bg="white",
res=300,
type="quartz"
)
h<-hist(prosport$HOUSE,
breaks=6,
col="red",
xlab="Districts Count per State",
ylab="Frequency",
main="Histogram of US House Districts Count",
ylim=c(0,40)
)
dev.off()