Platform
Resources
Pricing
Sign in
Get started
coopwr
Workspace
Fork
Published
By
coopwr
Edited
Mar 2, 2021
Fork of
Second Exercise on Observable: Classification and Colors
2
Insert cell
md
`# Second Exercise on Observable: Classification and Colors Will`
Insert cell
d3
=
require
(
"d3@5"
)
Insert cell
topojson
=
require
(
"topojson-client@3"
)
Insert cell
NYPD
=
FileAttachment
(
"NYCPolice.json"
)
.
json
(
)
Insert cell
county_features
=
topojson
.
feature
(
NYPD
,
NYPD
.
objects
.
NYCPolice
)
Insert cell
csv_data
=
d3
.
csvParse
(
await
FileAttachment
(
"NYCPolice.csv"
)
.
text
(
)
,
(
{
precinct
,
shape_area
,
shape_leng
}
)
=>
[
+
precinct
,
[
+
shape_area
/
+
shape_leng
]
]
)
Insert cell
shape_width
=
Array
.
from
(
csv_data
.
values
(
)
,
d
=>
d
[
1
]
[
0
]
)
Insert cell
data
=
Object
.
assign
(
new
Map
(
csv_data
)
,
{
title
:
[
"precinct number"
,
"Width"
]
}
)
Insert cell
3
md
`# Linear Scale (Unclassed)`
Insert cell
linear
=
d3
.
scaleLinear
(
)
.
domain
(
[
d3
.
min
(
shape_width
)
,
d3
.
max
(
shape_width
)
]
)
.
range
(
[
"#fee0d2"
,
"#de2d26"
]
)
Insert cell
chart
(
numericSort
(
shape_width
)
,
linear
)
Insert cell
md
`# Quantile Classification`
Insert cell
3
quantile
=
d3
.
scaleQuantile
(
)
.
domain
(
shape_width
)
.
range
(
[
"#fee5d9"
,
"#fcae91"
,
"#fb6a4a"
,
"#cb181d"
]
)
Insert cell
chart
(
numericSort
(
shape_width
)
,
quantile
)
Insert cell
1
md
`# Jenks Natural Breaks Classification`
Insert cell
naturalbreaks
=
simple
.
ckmeans
(
shape_width
,
3
)
.
map
(
v
=>
v
.
pop
(
)
)
Insert cell
jenks
=
d3
.
scaleThreshold
(
)
.
domain
(
naturalbreaks
)
.
range
(
[
"#fee5d9"
,
"#fcae91"
,
"#fb6a4a"
,
"#cb181d"
]
)
Insert cell
chart
(
numericSort
(
shape_width
)
,
jenks
)
Insert cell
1
md
`# Equal Interval Classification (Quantize)`
Insert cell
quantize
=
d3
.
scaleQuantize
(
)
.
domain
(
[
d3
.
min
(
shape_width
)
,
d3
.
max
(
shape_width
)
]
)
.
range
(
[
"#fee5d9"
,
"#fcae91"
,
"#fb6a4a"
,
"#cb181d"
]
)
Insert cell
chart
(
numericSort
(
shape_width
)
,
quantize
)
Insert cell
md
`# Threshold`
Insert cell
threshold
=
d3
.
scaleThreshold
(
)
.
domain
(
[
0.05
,
0.1
,
0.50
]
)
.
range
(
[
"#fee5d9"
,
"#fcae91"
,
"#fb6a4a"
,
"#cb181d"
]
)
Insert cell
chart
(
numericSort
(
shape_width
)
,
threshold
)
Insert cell
showScaleGrouping
(
shape_width
,
{
scaleQuantile
:
quantile
,
scaleThreshold
:
threshold
,
scaleJenks
:
jenks
,
scaleQuantize
:
quantize
,
scaleQuantizeNice
:
quantize
.
copy
(
)
.
nice
(
)
}
)
Insert cell
md
`# Annex`
Insert cell
Insert cell
Insert cell
simple
=
require
(
"simple-statistics@7.0.7/dist/simple-statistics.min.js"
)
Insert cell
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Compare fork
Fork
View
Export
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
topojson
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
NYPD
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
county_features
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
csv_data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
shape_width
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Show 3 comments
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
linear
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
quantile
Show 3 comments
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Show 1 comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
naturalbreaks
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
jenks
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Show 1 comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
quantize
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
threshold
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
numericSort
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
chart
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
simple
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
showScaleGrouping
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML