Platform
Resources
Pricing
Sign in
Get started
Caglar Koylu
Associate Professor of GIScience at the University of Iowa
Workspace
Fork
Published
By
Caglar Koylu
Edited
Mar 5, 2021
Fork of
Second Exercise on Observable: Classification and Colors
•
1 fork
2
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
US_counties
=
FileAttachment
(
"us_counties.json"
)
.
json
(
)
Insert cell
county_features
=
topojson
.
feature
(
US_counties
,
US_counties
.
objects
.
us_counties
)
Insert cell
csv_data
=
d3
.
csvParse
(
await
FileAttachment
(
"cb_2018_us_ua10_500k.csv"
)
.
text
(
)
,
(
{
GEOID10
,
AWATER10
,
ALAND10
}
)
=>
[
GEOID10
,
+
AWATER10
/
(
(
+
AWATER10
)
+
(
+
ALAND10
)
)
]
)
Insert cell
urbanarea
=
Array
.
from
(
csv_data
.
values
(
)
,
d
=>
d
[
1
]
)
.
filter
(
d
=>
d
!=
Infinity
)
Insert cell
perurban
=
Object
.
assign
(
new
Map
(
csv_data
)
,
{
title
:
[
"County"
,
"Area of Land and Water in US Counties"
]
}
)
Insert cell
md
`# Linear Scale (Unclassed)`
Insert cell
linear
=
d3
.
scaleLinear
(
)
.
domain
(
[
d3
.
min
(
urbanarea
)
,
d3
.
max
(
urbanarea
)
]
)
.
range
(
[
"#e0ecf4"
,
"#8856a7"
]
)
Insert cell
chart
(
numericSort
(
urbanarea
)
,
linear
)
Insert cell
mycolors
=
[
"#e0ecf4"
,
"#99d594"
,
"#8856a7"
]
Insert cell
md
`# Quantile Classification`
Insert cell
quantile
=
d3
.
scaleQuantile
(
)
.
domain
(
urbanarea
)
.
range
(
mycolors
)
Insert cell
chart
(
numericSort
(
urbanarea
)
,
quantile
)
Insert cell
md
`# Jenks Natural Breaks Classification`
Insert cell
naturalbreaks
=
simple
.
ckmeans
(
urbanarea
,
mycolors
.
length
)
.
map
(
v
=>
v
.
pop
(
)
)
Insert cell
jenks
=
d3
.
scaleThreshold
(
)
.
domain
(
naturalbreaks
)
.
range
(
mycolors
)
Insert cell
chart
(
numericSort
(
urbanarea
)
,
jenks
)
Insert cell
md
`# Equal Interval Classification (Quantize)`
Insert cell
quantize
=
d3
.
scaleQuantize
(
)
.
domain
(
[
d3
.
min
(
urbanarea
)
,
d3
.
max
(
urbanarea
)
]
)
.
range
(
mycolors
)
Insert cell
chart
(
numericSort
(
urbanarea
)
,
quantize
)
Insert cell
md
`# Threshold`
Insert cell
threshold
=
d3
.
scaleThreshold
(
)
.
domain
(
[
0.05
,
0.1
,
0.2
,
,
d3
.
max
(
urbanarea
)
]
)
.
range
(
mycolors
)
Insert cell
chart
(
numericSort
(
urbanarea
)
,
threshold
)
Insert cell
showScaleGrouping
(
urbanarea
,
{
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
US_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
urbanarea
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
perurban
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
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
mycolors
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
quantile
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
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
Add 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