Platform
Resources
Pricing
Sign in
Get started
Ross Stewart
Workspace
Fork
Public
By
Ross Stewart
Edited
Mar 31, 2023
2
Insert cell
Insert cell
viewof
slope
=
Inputs
.
range
(
[
0
,
10
]
,
{
step
:
.1
,
label
:
"slope"
}
)
Insert cell
viewof
intercept
=
Inputs
.
range
(
[
0
,
30
]
,
{
step
:
.1
,
label
:
"intercept"
}
)
Insert cell
viewof
species
=
Inputs
.
radio
(
[
"Chinstrap"
,
"Gentoo"
]
,
{
value
:
"Chinstrap"
}
,
{
label
:
"species"
}
)
Insert cell
html
`<div style = "
display:grid;
grid-template-areas:
'a b';
grid-gap: 10px;
">
<div style = "grid-area:a;border:1px solid black;">${
plot1
}</div>
<div style = "grid-area:b;border: 1px solid black">${
plot2
}</div>
</div>`
Insert cell
plot1
=
Plot
.
plot
(
{
y
:
{
domain
:
[
0
,
30
]
}
,
marks
:
[
Plot
.
dot
(
beaklength
,
{
x
:
beaklength
,
y
:
beakdepth
,
fill
:
"black"
}
)
,
Plot
.
line
(
endPoints
,
{
stroke
:
"red"
}
)
,
Plot
.
ruleX
(
[
0
]
)
,
Plot
.
ruleY
(
[
0
]
)
]
}
)
Insert cell
plot2
=
Plot
.
plot
(
{
y
:
{
domain
:
[
0
,
30
]
}
,
marks
:
[
Plot
.
dot
(
beaklength2
,
{
x
:
beaklength2
,
y
:
beakdepth2
,
fill
:
"black"
}
)
,
Plot
.
line
(
endPoints
,
{
stroke
:
"red"
}
)
,
Plot
.
ruleX
(
[
0
]
)
,
Plot
.
ruleY
(
[
0
]
)
]
}
)
Insert cell
penguins
=
FileAttachment
(
"penguins.json"
)
.
json
(
)
Insert cell
data1
=
penguins
.
filter
(
d
=>
d
[
"Beak Length (mm)"
]
!=
null
)
.
filter
(
d
=>
d
[
"Beak Depth (mm)"
]
!=
null
)
.
filter
(
d
=>
d
.
Species
==
"Adelie"
)
Insert cell
data2
=
penguins
.
filter
(
d
=>
d
[
"Beak Length (mm)"
]
!=
null
)
.
filter
(
d
=>
d
[
"Beak Depth (mm)"
]
!=
null
)
.
filter
(
d
=>
d
.
Species
==
species
)
Insert cell
beaklength
=
data1
.
map
(
d
=>
d
[
"Beak Length (mm)"
]
)
Insert cell
beaklength2
=
data2
.
map
(
d
=>
d
[
"Beak Length (mm)"
]
)
Insert cell
beakdepth
=
data1
.
map
(
d
=>
d
[
"Beak Depth (mm)"
]
)
Insert cell
beakdepth2
=
data2
.
map
(
d
=>
d
[
"Beak Depth (mm)"
]
)
Insert cell
yhat
=
beaklength
.
map
(
d
=>
slope
*
d
+
intercept
)
Insert cell
differences
=
beaklength
.
map
(
(
d
,
i
)
=>
beakdepth
[
i
]
-
yhat
[
i
]
)
Insert cell
squares
=
differences
.
map
(
d
=>
d
*
d
)
Insert cell
endPoints
=
[
[
0
,
slope
*
0
+
intercept
]
,
[
60
,
slope
*
60
+
intercept
]
]
Insert cell
d3
.
max
(
data1
,
d
=>
d
[
"Beak Length (mm)"
]
)
Insert cell
d3
.
max
(
data1
,
d
=>
d
[
"Beak Depth (mm)"
]
)
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
slope
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
intercept
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
species
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
plot1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
plot2
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
penguins
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data1
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data2
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
beaklength
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
beaklength2
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
beakdepth
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
beakdepth2
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
yhat
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
differences
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
squares
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
endPoints
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