Platform
Resources
Pricing
Sign in
Get started
masterkeef93
Workspace
Fork
Public
By
masterkeef93
Edited
Feb 18, 2023
Fork of
Second Exercise on Observable: Classification and Colors
5
Insert cell
md
`# Second Exercise on Observable: Classification and Colors`
Insert cell
Insert cell
Insert cell
Insert cell
d3
=
require
(
"d3@5"
)
Insert cell
topojson
=
require
(
"topojson-client@3"
)
Insert cell
counties
=
FileAttachment
(
"JHU_US_Counties.json"
)
.
json
(
)
Insert cell
counties_features
=
topojson
.
feature
(
counties
,
counties
.
objects
.
JHU_Counties
)
Insert cell
Insert cell
// How do I view the column names for my csv?
county_covid
=
FileAttachment
(
"NH_county_vaccines.csv"
)
.
csv
(
)
;
Insert cell
col_names
=
Object
.
keys
(
county_covid
[
0
]
)
;
Insert cell
md
`The column names are: \`${
col_names
}\``
;
Insert cell
Insert cell
Insert cell
csv_data
=
d3
.
csvParse
(
await
FileAttachment
(
"NH_county_vaccines.csv"
)
.
text
(
)
,
(
{
fips
,
recent_percentage_of_current_residents_who_received_a_completed_covid_19_vaccination_at_any_time
}
)
=>
[
fips
,
+
recent_percentage_of_current_residents_who_received_a_completed_covid_19_vaccination_at_any_time
]
)
Insert cell
csv_data_objects
=
Object
.
assign
(
(
d3
.
csvParse
(
await
FileAttachment
(
"NH_county_vaccines.csv"
)
.
text
(
)
,
d3
.
autoType
)
)
.
map
(
(
{
fips
,
recent_percentage_of_current_residents_who_received_a_completed_covid_19_vaccination_at_any_time
}
)
=>
(
{
fips
:
+
fips
,
pctResVac
:
+
recent_percentage_of_current_residents_who_received_a_completed_covid_19_vaccination_at_any_time
}
)
)
)
Insert cell
viewof
bins
=
Inputs
.
range
(
[
0
,
100
]
,
{
step
:
10
,
label
:
"Bins"
}
)
Insert cell
Plot
.
plot
(
{
marks
:
[
Plot
.
rectY
(
csv_data_objects
,
Plot
.
binX
(
{
y
:
"count"
}
,
{
x
:
"pctResVac"
,
thresholds
:
bins
}
)
)
,
Plot
.
ruleY
(
[
0
]
)
]
}
)
Insert cell
resPct
=
Array
.
from
(
csv_data
.
values
(
)
,
d
=>
d
[
1
]
)
Insert cell
data
=
Object
.
assign
(
new
Map
(
csv_data
)
,
{
title
:
[
"Percent Vaccinated Nursing Home Residents"
]
}
)
Insert cell
md
`# Linear Scale (Unclassed)`
Insert cell
linear
=
d3
.
scaleLinear
(
)
.
domain
(
d3
.
extent
(
resPct
)
)
.
range
(
[
"white"
,
"green"
]
)
Insert cell
chart
(
numericSort
(
resPct
)
,
linear
)
Insert cell
md
`# Quantile Classification`
Insert cell
quantile
=
d3
.
scaleQuantile
(
)
.
domain
(
resPct
)
.
range
(
[
"white"
,
"#99d594"
,
"green"
]
)
Insert cell
chart
(
numericSort
(
resPct
)
,
quantile
)
Insert cell
md
`# Jenks Natural Breaks Classification`
Insert cell
naturalbreaks
=
simple
.
ckmeans
(
resPct
,
3
)
.
map
(
v
=>
v
.
pop
(
)
)
Insert cell
jenks
=
d3
.
scaleThreshold
(
)
.
domain
(
naturalbreaks
)
.
range
(
[
"white"
,
"#99d594"
,
"green"
]
)
Insert cell
chart
(
numericSort
(
resPct
)
,
jenks
)
Insert cell
md
`# Equal Interval Classification (Quantize)`
Insert cell
quantize
=
d3
.
scaleQuantize
(
)
.
domain
(
[
d3
.
min
(
resPct
)
,
d3
.
max
(
resPct
)
]
)
.
range
(
[
"#fde0dd"
,
"#fa9fb5"
,
"#c51b8a"
]
)
Insert cell
chart
(
numericSort
(
resPct
)
,
quantize
)
Insert cell
md
`# Threshold`
Insert cell
threshold
=
d3
.
scaleThreshold
(
)
.
domain
(
[
0.05
,
0.1
,
0.2
]
)
.
range
(
[
"white"
,
"#99d594"
,
"green"
]
)
Insert cell
chart
(
numericSort
(
resPct
)
,
threshold
)
Insert cell
showScaleGrouping
(
resPct
,
{
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
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
counties_features
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
county_covid
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
col_names
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
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
resPct
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
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
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