Platform
Resources
Pricing
Sign in
Contact us
Visionscarto
Maps — and other representations of the world.
Workspace
Fork
Published
#30DayMapChallenge
By
Fil
Edited
Nov 22, 2021
3 stars
4
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
druid
=
require
(
"@saehrimnir/druidjs@0.3.16"
)
Insert cell
Insert cell
districts
=
new
Set
(
flows
.
map
(
(
d
)
=>
d
.
CODEi
)
)
Insert cell
matrix
=
{
const
index
=
d3
.
index
(
flows
,
(
d
)
=>
d
.
CODEi
,
(
d
)
=>
d
.
CODEj
)
;
return
Array
.
from
(
districts
,
(
i
)
=>
Array
.
from
(
districts
,
(
j
)
=>
index
.
get
(
i
)
.
get
(
j
)
.
Fij
)
)
;
}
Insert cell
Insert cell
positions
=
{
const
X
=
druid
.
Matrix
.
from
(
matrix
)
;
// X is the data as object of the Matrix class.
return
new
druid
[
"UMAP"
]
(
X
,
10
,
1
,
1
,
2
)
.
transform
(
)
.
_data
;
}
Insert cell
X
=
positions
.
filter
(
(
_
,
i
)
=>
i
%
2
===
0
)
Insert cell
Y
=
positions
.
filter
(
(
_
,
i
)
=>
i
%
2
===
1
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot
.
dot
(
districts
,
{
x
:
X
,
y
:
Y
,
fill
:
his
,
r
:
7
}
)
.
plot
(
{
x
:
{
label
:
"← first UMAP dimension"
,
reverse
:
true
,
axis
:
"top"
}
,
y
:
{
label
:
"↓ second UMAP dimension"
,
reverse
:
true
,
axis
:
"right"
}
,
color
:
{
scheme
:
"tableau10"
}
}
)
Insert cell
Insert cell
simple
=
import
(
"simple-statistics@7"
)
Insert cell
positions1
=
{
const
X
=
druid
.
Matrix
.
from
(
matrix
)
;
// X is the data as object of the Matrix class.
return
new
druid
[
"UMAP"
]
(
X
,
5
,
1
,
1
,
1
)
.
transform
(
)
.
_data
;
}
Insert cell
thresholds
=
simple
.
ckmeans
(
positions1
,
3
)
.
slice
(
1
)
.
map
(
(
g
)
=>
d3
.
min
(
g
)
)
Insert cell
clusters
=
Array
.
from
(
positions1
,
(
d
)
=>
d
<
thresholds
[
0
]
?
"cluster A"
:
d
<
thresholds
[
1
]
?
"cluster B"
:
"cluster C"
)
Insert cell
Insert cell
clustMap
=
Plot
.
dot
(
districts
,
{
x
:
X
,
y
:
Y
,
fill
:
clusters
,
r
:
7
}
)
.
plot
(
{
x
:
{
label
:
"← first UMAP dimension"
,
reverse
:
true
,
axis
:
"top"
}
,
y
:
{
label
:
"↓ second UMAP dimension"
,
reverse
:
true
,
axis
:
"right"
}
,
color
:
{
scheme
:
"category10"
}
}
)
Insert cell
Insert cell
Insert cell
Insert cell
classColor
=
{
const
{
domain
,
range
}
=
clustMap
.
scale
(
"color"
)
;
const
a
=
d3
.
scaleOrdinal
(
domain
,
range
)
;
return
(
i
)
=>
a
(
clusters
[
i
]
)
;
}
Insert cell
Insert cell
Insert cell
umapColor1
=
{
const
c
=
d3
.
scaleSequential
(
[
-
2
,
5
]
,
d3
.
interpolateWarm
)
;
return
(
i
)
=>
c
(
positions1
[
i
]
)
;
}
Insert cell
map
(
umapColor1
)
Insert cell
umapColor2
=
{
const
k
=
80
;
return
(
i
)
=>
d3
.
lab
(
40
,
k
*
(
X
[
i
]
+
2
*
Y
[
i
]
)
,
k
*
(
X
[
i
]
-
Y
[
i
]
)
)
;
}
Insert cell
map
(
umapColor2
)
Insert cell
Insert cell
land
=
FileAttachment
(
"land.json"
)
.
json
(
)
Insert cell
points
=
FileAttachment
(
"coordinates.csv"
)
.
csv
(
)
.
then
(
(
data
)
=>
new
Map
(
data
.
map
(
(
{
X_dd
:
lat
,
Y_dd
:
lon
,
CODE114
:
code
}
)
=>
[
code
,
[
+
lon
,
+
lat
]
]
)
)
)
Insert cell
projection
=
d3
.
geoMercator
(
)
.
fitExtent
(
[
[
20
,
30
]
,
[
width
-
20
,
width
*
0.45
-
30
]
]
,
land
)
Insert cell
legend
=
(
{
domain
,
range
}
)
=>
Swatches
(
d3
.
scaleOrdinal
(
domain
,
range
)
)
Insert cell
import
{
Swatches
}
from
"@d3/color-legend"
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
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
flows
Edit
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
druid
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
districts
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
matrix
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
positions
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
X
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Y
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
type
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
rep
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
his
Edit
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
repMap
Edit
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
hisMap
Edit
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
simple
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
positions1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
thresholds
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
clusters
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
clustMap
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
classColor
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
umapColor1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
umapColor2
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
map
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
land
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
points
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
projection
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
legend
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML