Platform
Resources
Pricing
Sign in
Get started
Geoviz
Workspace
Fork
Public
By
Audrey Hoey-Kummerow
Edited
Feb 20
Fork of
Second Exercise on Observable: Classification and Colors
4
Insert cell
md
`# Classifying the Percent of Women over 25 with Bachelor's Degrees in Iowa Counties`
Insert cell
d3
=
require
(
"d3@5"
)
Insert cell
topojson
=
require
(
"topojson-client@3"
)
Insert cell
1
Counties
=
FileAttachment
(
"US_County_2020_WGS84.json"
)
.
json
(
)
Insert cell
1
county_features
=
topojson
.
feature
(
Counties
,
Counties
.
objects
.
US_County_2020_WGS84
)
Insert cell
1
csv_data
=
d3
.
csvParse
(
await
FileAttachment
(
"Education.csv"
)
.
text
(
)
,
(
{
STATE
,
COUNTY
,
ASP2E032
,
ASP2E019
}
)
=>
STATE
===
"Iowa"
?
[
COUNTY
,
(
+
ASP2E032
/
+
ASP2E019
)
*
100
]
:
null
)
.
filter
(
d
=>
d
)
;
Insert cell
1
csv_data_objects
=
d3
.
csvParse
(
await
FileAttachment
(
"Education.csv"
)
.
text
(
)
,
d3
.
autoType
)
.
map
(
(
{
STATE
,
COUNTY
,
ASP2E032
,
ASP2E019
}
)
=>
STATE
===
"Iowa"
?
{
County
:
COUNTY
,
pctWomenWithBachelors
:
(
+
ASP2E032
/
+
ASP2E019
)
*
100
}
:
null
)
.
filter
(
d
=>
d
)
;
Insert cell
viewof
bins
=
Inputs
.
range
(
[
0
,
40
]
,
{
step
:
1
,
label
:
"Bins"
}
)
Insert cell
1
Plot
.
plot
(
{
marks
:
[
Plot
.
rectY
(
csv_data_objects
,
Plot
.
binX
(
{
y
:
"count"
}
,
{
x
:
"pctWomenWithBachelors"
,
thresholds
:
bins
}
)
)
,
Plot
.
ruleY
(
[
0
]
)
]
}
)
Insert cell
1
pctWomenWithBahcelors
=
Array
.
from
(
csv_data
.
values
(
)
,
d
=>
d
[
1
]
)
Insert cell
1
data
=
Object
.
assign
(
new
Map
(
csv_data
)
,
{
title
:
[
"Percent of Women in Iowa with a Bachelor's Degree: 25 and Older"
]
}
)
Insert cell
md
`# Linear Scale (Unclassed)`
Insert cell
1
unclassed
=
d3
.
scaleLinear
(
)
.
domain
(
d3
.
extent
(
pctWomenWithBahcelors
)
)
.
range
(
[
"#fee6ce"
,
"#e6550d"
]
)
Insert cell
chart
(
numericSort
(
pctWomenWithBahcelors
)
,
unclassed
)
Insert cell
md
`# Quantile Classification`
Insert cell
1
quantile
=
d3
.
scaleQuantile
(
)
.
domain
(
pctWomenWithBahcelors
)
.
range
(
[
"#f2f0f7"
,
"#cbc9e2"
,
"#9e9ac8"
,
"#6a51a3"
]
)
Insert cell
chart
(
numericSort
(
pctWomenWithBahcelors
)
,
quantile
)
Insert cell
md
`# Jenks Natural Breaks Classification`
Insert cell
1
naturalbreaks
=
simple
.
ckmeans
(
pctWomenWithBahcelors
,
4
)
.
map
(
v
=>
v
.
pop
(
)
)
Insert cell
1
jenks
=
d3
.
scaleThreshold
(
)
.
domain
(
naturalbreaks
)
.
range
(
[
"#edf8e9"
,
"#bae4b3"
,
"#74c476"
,
"#31a354"
,
"#006d2c"
]
)
Insert cell
chart
(
numericSort
(
pctWomenWithBahcelors
)
,
jenks
)
Insert cell
md
`# Equal Interval Classification (Quantize)`
Insert cell
1
quantize
=
d3
.
scaleQuantize
(
)
.
domain
(
[
d3
.
min
(
pctWomenWithBahcelors
)
,
d3
.
max
(
pctWomenWithBahcelors
)
]
)
.
range
(
[
"#eff3ff"
,
"#bdd7e7"
,
"#6baed6"
,
"#3182bd"
,
"#08519c"
]
)
Insert cell
chart
(
numericSort
(
pctWomenWithBahcelors
)
,
quantize
)
Insert cell
md
`# Threshold`
Insert cell
1
threshold
=
d3
.
scaleThreshold
(
)
.
domain
(
[
14
,
18
,
21
,
27
]
)
.
range
(
[
"#fee5d9"
,
"#fcae91"
,
"#fb6a4a"
,
"#de2d26"
,
"#a50f15"
]
)
Insert cell
d3
.
min
(
pctWomenWithBahcelors
)
Insert cell
d3
.
max
(
pctWomenWithBahcelors
)
Insert cell
1
chart
(
numericSort
(
pctWomenWithBahcelors
)
,
threshold
)
Insert cell
showScaleGrouping
(
pctWomenWithBahcelors
,
{
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
Counties
Show 1 comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
county_features
Show 1 comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
csv_data
Show 1 comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
csv_data_objects
Show 1 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
Show 1 comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
pctWomenWithBahcelors
Show 1 comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data
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
unclassed
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
quantile
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
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
Add 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
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
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
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