Platform
Resources
Pricing
Sign in
Get started
GEOG 3540
Workspace
Fork
Public
By
Tat-long
Edited
Feb 19
Fork of
Second Exercise on Observable: Classification and Colors
4
Insert cell
md
`# Second Exercise on Observable: Classification and Colors`
Insert cell
d3
=
require
(
"d3@5"
)
Insert cell
topojson
=
require
(
"topojson-client@3"
)
Insert cell
MI_Counties
=
FileAttachment
(
"MI_Counties_WGS1984.json"
)
.
json
(
)
Insert cell
county_features
=
topojson
.
feature
(
MI_Counties
,
MI_Counties
.
objects
.
MI_Counties_WGS1984
)
Insert cell
csv_data
=
d3
.
csvParse
(
await
FileAttachment
(
"MI_Education (2).csv"
)
.
text
(
)
,
(
{
FIPS
,
Percent
}
)
=>
[
FIPS
,
+
Percent
]
)
Insert cell
csv_data_objects
=
Object
.
assign
(
(
d3
.
csvParse
(
await
FileAttachment
(
"MI_Education (2).csv"
)
.
text
(
)
,
d3
.
autoType
)
)
.
map
(
(
{
FIPS
,
Percent
}
)
=>
(
{
FIPS
,
Percent
}
)
)
)
Insert cell
viewof
bins
=
Inputs
.
range
(
[
0
,
20
]
,
{
step
:
1
,
label
:
"Bins"
}
)
Insert cell
Plot
.
plot
(
{
marks
:
[
Plot
.
rectY
(
csv_data_objects
,
Plot
.
binX
(
{
y
:
"count"
}
,
{
x
:
"Percent"
,
thresholds
:
bins
}
)
)
,
Plot
.
ruleY
(
[
0
]
)
]
}
)
Insert cell
PctDegree
=
Array
.
from
(
csv_data
.
values
(
)
,
d
=>
d
[
1
]
)
Insert cell
data
=
Object
.
assign
(
new
Map
(
csv_data
)
,
{
title
:
[
"Percent Population of Michigan with Bachelors Degree"
]
}
)
Insert cell
1
md
`# Linear Scale (Unclassed)`
Insert cell
d3
.
max
(
PctDegree
)
Insert cell
d3
.
min
(
PctDegree
)
Insert cell
1
linear
=
d3
.
scaleLinear
(
)
.
domain
(
d3
.
extent
(
PctDegree
)
)
.
range
(
[
"white"
,
"red"
]
)
Insert cell
chart
(
numericSort
(
PctDegree
)
,
linear
)
Insert cell
1
md
`# Quantile Classification`
Insert cell
1
quantile
=
d3
.
scaleQuantile
(
)
.
domain
(
PctDegree
)
.
range
(
[
"#efedf5"
,
"#bcbddc"
,
"#8856a7"
]
)
Insert cell
1
chart
(
numericSort
(
PctDegree
)
,
quantile
)
Insert cell
md
`# Jenks Natural Breaks Classification`
Insert cell
1
naturalbreaks
=
simple
.
ckmeans
(
PctDegree
,
3
)
.
map
(
v
=>
v
.
pop
(
)
)
Insert cell
1
jenks
=
d3
.
scaleThreshold
(
)
.
domain
(
naturalbreaks
)
.
range
(
[
"#fee6ce"
,
"#fdae6b"
,
"#e6550d"
]
)
Insert cell
chart
(
numericSort
(
PctDegree
)
,
jenks
)
Insert cell
1
md
`# Equal Interval Classification (Quantize)`
Insert cell
1
quantize
=
d3
.
scaleQuantize
(
)
.
domain
(
[
d3
.
min
(
PctDegree
)
,
d3
.
max
(
PctDegree
)
]
)
.
range
(
[
"#fde0dd"
,
"#fa9fb5"
,
"#c51b8a"
]
)
Insert cell
chart
(
numericSort
(
PctDegree
)
,
quantize
)
Insert cell
md
`# Threshold`
Insert cell
threshold
=
d3
.
scaleThreshold
(
)
.
domain
(
[
20
,
30
,
40
]
)
.
range
(
[
"white"
,
"#a6bddb"
,
"#2b8cbe"
]
)
Insert cell
chart
(
numericSort
(
PctDegree
)
,
threshold
)
Insert cell
showScaleGrouping
(
PctDegree
,
{
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
MI_Counties
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
csv_data_objects
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
bins
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
PctDegree
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 1 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
linear
Show 1 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
quantile
Show 1 comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Show 1 comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
naturalbreaks
Show 1 comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
jenks
Show 1 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
Show 1 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