Platform
Resources
Pricing
Sign in
Contact us
Andy Reagan
Senior Data Scientist, MassMutual Lecturer, UC Berkeley MIDS -- PhD Applied Math, Computational Story Lab, UVM MS Applied Math, UVM BS Math, Virginia Tech
Workspace
Fork
Public
By
Andy Reagan
Edited
Apr 3, 2023
Insert cell
Insert cell
+
d
[
0
]
.
Year
.
slice
(
0
,
4
)
Insert cell
// year_range = d3.extent(d, x => +x.Year.slice(0, 4))
year_range
=
[
1970
,
1982
]
Insert cell
viewof
year
=
Inputs
.
range
(
year_range
,
{
value
:
year_range
[
0
]
,
step
:
1
,
label
:
"Min. Year"
}
)
Insert cell
viewof
color
=
Inputs
.
radio
(
[
"Year"
,
"Origin"
,
"Cylinders"
]
,
{
label
:
"Color by"
,
value
:
"Origin"
}
)
Insert cell
plot
=
Plot
.
plot
(
{
marks
:
[
// Plot.dot(d.filter(x => +x.Year.slice(0, 4) > year), {x: "Horsepower", y: "Displacement", stroke: color})
Plot
.
dot
(
d
,
{
x
:
"Horsepower"
,
y
:
"Displacement"
,
stroke
:
color
}
)
]
}
)
Insert cell
d
.
filter
(
x
=>
x
.
Year
.
slice
(
0
,
4
)
>
year
)
Insert cell
Insert cell
jsonURL
=
`/api/${
year
}/`
// jsonURL = data['cars.json'].url
Insert cell
d
=
fetch
(
jsonURL
)
.
then
(
response
=>
{
if
(
!
response
.
ok
)
throw
new
Error
(
response
.
status
)
;
return
response
.
json
(
)
;
}
)
// d = data['cars.json']()
Insert cell
x
=
fetch
(
jsonURL
)
.
then
(
response
=>
{
if
(
!
response
.
ok
)
throw
new
Error
(
response
.
status
)
;
return
response
.
json
(
)
;
}
)
Insert cell
data
=
require
(
'vega-datasets@2'
)
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
year_range
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
year
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
color
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
plot
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
jsonURL
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d
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
data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML