-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstateBarCountyScatter.html
162 lines (145 loc) · 6.75 KB
/
stateBarCountyScatter.html
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<div w3-include-html="header.html"></div>
<script src="https://www.w3schools.com/lib/w3.js"></script>
<script>
w3.includeHTML();
</script>
<script>
function bottomNav(arr) {
const out =
`<div class="container">
<div class="col-lg-2 text-left">
<a href="${arr[0][0]}">
<button type="button" class="btn btn-default btn-xs btn-default">
${arr[0][1]}<span class="glyphicon glyphicon-home" aria-hidden="true"></span>
</button>
</a>
</div>
<div class="col-lg-8 text-center">
<a href="${arr[1][0]}">
<button type="button" class="btn btn-default btn-xs btn-default">
${arr[1][1]}<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
</button>
</a>
</div>
<div class="col-lg-2 text-right">
<a href="${arr[2][0]}">
<button type="button" class="btn btn-default btn-xs btn-default">
${arr[2][1]}<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
</button>
</a>
</div>
</div>`;
return out;
}
</script>
<script>
document.write(bottomNav([['crmain.html', 'Home'], ['stateCrime.html', 'State Crime'], ['countyCrime.html', 'Country Crime Summary']]));
</script>
<div w3-include-html="footer.html"></div>
<xmp theme="united" style="display:none;">
### 4. Combined State and County Crime Rates View
Notes:
- The County Level Scatterplot indicates some outliers of high crime rates in *both* rural (low population density) *and* urban areas (high population density).
- *Alaska* in particular has instances of very low population density counties with high crime rate (per ***capita*** *not* ***area***!)
- *St Louis City* is an opposite extreme: high crame rate in an urban environment
</xmp>
<div class="container">
<div class="container" id="vegaChart">
<div class="secondVis" id="countyCrime">
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/topojson/1.1.0/topojson.min.js"></script>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega-lite/2.0.0-beta.3/vega-lite.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega/3.0.0-beta.31/vega.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega-embed/3.0.0-beta.14/vega-embed.js"></script>
<link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/vega-tooltip/0.3.3/vega-tooltip.min.css"></link>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega-tooltip/0.3.3/vega-tooltip.min.js"></script>
<script>
var opt = {
mode: "vega-lite",
actions: false
};
const countySpec = {
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"description": "Drag out a rectangular brush to highlight points.",
"data": {
"url": "data/combinedData2.json"
},
<!--"transform": [-->
<!--{"bin": {"maxbins":10}, "type": "quantitative", "field": "County_Population_Density", "as" : "County_Population_Density_Bin"},-->
<!--{"bin": null , "field": "County_Crime_Rate", "as" : "County_Crime_Rate_Bin"},-->
<!--{"bin": null , "field": "State_Population_Density", "as" : "State_Population_Density_Bin"},-->
<!--{"bin": null , "field": "State_Crime_Rate", "as" : "State_Crime_Rate_Bin"},-->
<!--{"calculate": "datum.County_Total_Crimes / datum.County_Population", "as" : "County_Crime_Rate_Calc"},-->
<!--{"calculate": "datum.County_Total_Crimes / datum.County_Area", "as" : "County_Crime_Density"},-->
<!--{"calculate": "datum.State_Total_Crimes / datum.State_Area", "as" : "State_Crime_Density"},-->
<!--{"summarize": [-->
<!--{"aggregate": "sum", "field": "County_Population", "as" : "State_Population_Calc"}-->
<!--]-->
<!--}-->
<!--],-->
"vconcat" : [
{
"selection": {
"brush": {
"type": "multi"
}
},
"width": 900,
"height": 300,
"mark": "bar",
"encoding": {
"x": {"field": "State", "type": "nominal", "legend": false},
"y": {"field": "State_Crime_Rate", "type": "quantitative", "scale": {"type": "log"}, "legend": false},
"color": {"field": "State", "type": "nominal", "legend": false},
},
"config": {
"legend": false
}
},
{
"selection": {
"brush": {
"type": "multi"
}
},
"width": 900,
"height": 300,
"mark": "point",
"encoding": {
"x": {"field": "County_Population_Density", "type": "quantitative", "scale": {"type": "log"}},
"y": {"field": "County_Crime_Rate", "type": "quantitative", "scale": {"type": "log"}},
"color": {"field": "State", "type": "nominal"}
// "tooltip": {"field": "County", "type": "nominal"}
}
}
]
};
vega.embed("#countyCrime", countySpec, opt, function (error, result) {
console.log(error);
var tooltipOption = {
showAllFields: false,
fields: [
{field: "State", title: "State"},
{field: "State_Crime_Rate", title: "State Crime Rate"},
{field: "County", title: "County"},
{field: "County_Area", title: "County Geographical Area"},
{field: "County_Population", title: "County Population"},
{field: "County_Population_Density", title: "County Population Density"},
{field: "County_Crime_Rate", title: "County Crime Rate"},
{field: "County_Total_Crimes", title: "County Total Crimes"}
]
};
vegaTooltip.vegaLite(result.view, countySpec, tooltipOption);
});
</script>
<script src="strapdown.js"></script>
<script>setTimeout(function(){document.getElementById('stateCountyTab').className = 'active';},100);</script>