Platform
Resources
Pricing
Sign in
Get started
Camille Lust
Workspace
Fork
Public
By
Camille Lust
Edited
Feb 21, 2023
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
counties
=
FileAttachment
(
"County2010washWGS84.json"
)
.
json
(
)
Insert cell
county_features
=
topojson
.
feature
(
counties
,
counties
.
objects
.
County2010washWGS84
)
Insert cell
1
csv_data
=
d3
.
csvParse
(
await
FileAttachment
(
"County2010washWGS84.dbf.csv"
)
.
text
(
)
,
(
{
COUNTYFP10
,
POPWHITE
,
POP10
}
)
=>
[
COUNTYFP10
,
+
POPWHITE
/
+
POP10
]
)
Insert cell
csv_data_objects
=
Object
.
assign
(
(
d3
.
csvParse
(
await
FileAttachment
(
"County2010washWGS84.dbf.csv"
)
.
text
(
)
,
d3
.
autoType
)
)
.
map
(
(
{
COUNTYFP10
,
POPWHITE
,
POP10
}
)
=>
(
{
FIPS
:
+
COUNTYFP10
,
pctwhite
:
+
POPWHITE
/
+
POP10
}
)
)
)
Insert cell
1
viewof
bins
=
Inputs
.
range
(
[
0
,
100
]
,
{
step
:
1
,
label
:
"Bins"
}
)
Insert cell
Plot
.
plot
(
{
marks
:
[
Plot
.
rectY
(
csv_data_objects
,
Plot
.
binX
(
{
y
:
"count"
}
,
{
x
:
"pctwhite"
,
thresholds
:
bins
}
)
)
,
Plot
.
ruleY
(
[
0
]
)
]
}
)
Insert cell
whitepct
=
Array
.
from
(
csv_data
.
values
(
)
,
d
=>
d
[
1
]
)
Insert cell
data
=
Object
.
assign
(
new
Map
(
csv_data
)
,
{
title
:
[
"Percent Population of Washington That is White"
]
}
)
Insert cell
md
`# Linear Scale (Unclassed)`
Insert cell
d3
.
min
(
whitepct
)
Insert cell
d3
.
max
(
whitepct
)
Insert cell
3
unclassed
=
d3
.
scaleLinear
(
)
.
domain
(
d3
.
extent
(
whitepct
)
)
.
range
(
[
"#edf8b1"
,
"#2c7fb8"
]
)
Insert cell
1
chart
(
numericSort
(
whitepct
)
,
unclassed
)
Insert cell
md
`# Quantile Classification`
Insert cell
3
quantile
=
d3
.
scaleQuantile
(
)
.
domain
(
whitepct
)
.
range
(
[
"#fde0dd"
,
"#fa9fb5"
,
"#c51b8a"
]
)
Insert cell
chart
(
numericSort
(
whitepct
)
,
quantile
)
Insert cell
md
`# Jenks Natural Breaks Classification`
Insert cell
naturalbreaks
=
simple
.
ckmeans
(
whitepct
,
3
)
.
map
(
v
=>
v
.
pop
(
)
)
Insert cell
4
jenks
=
d3
.
scaleThreshold
(
)
.
domain
(
naturalbreaks
)
.
range
(
[
"#e7e1ef"
,
"#c994c7"
,
"#dd1c77"
]
)
Insert cell
chart
(
numericSort
(
whitepct
)
,
jenks
)
Insert cell
md
`# Equal Interval Classification (Quantize)`
Insert cell
1
d3
.
extent
(
whitepct
)
Insert cell
2
quantize
=
d3
.
scaleQuantize
(
)
.
domain
(
[
d3
.
min
(
whitepct
)
,
d3
.
max
(
whitepct
)
]
)
.
range
(
[
"#f6eff7"
,
"#bdc9e1"
,
"#67a9cf"
,
"#02818a"
]
)
Insert cell
chart
(
numericSort
(
whitepct
)
,
quantize
)
Insert cell
md
`# Threshold`
Insert cell
d3
.
min
(
whitepct
)
Insert cell
1
d3
.
max
(
whitepct
)
Insert cell
2
threshold
=
d3
.
scaleThreshold
(
)
.
domain
(
[
0.7
,
0.8
]
)
.
range
(
[
"#fee8c8"
,
"#e34a33"
]
)
Insert cell
chart
(
numericSort
(
whitepct
)
,
threshold
)
Insert cell
showScaleGrouping
(
whitepct
,
{
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
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
Show 1 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
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
whitepct
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
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
unclassed
Show 3 comments
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
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
Add 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
Show 4 comments
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
quantize
Show 2 comments
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
Show 1 comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
threshold
Show 2 comments
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