Platform
Solutions
Resources
Pricing
Sign in
Sign up
laurent smeets
Workspace
Fork
Public
By
laurent smeets
Edited
Jul 12, 2023
Fork of
Plot: Simpsons ratings
3
Insert cell
Insert cell
Plot
.
plot
(
{
padding
:
0
,
x
:
{
axis
:
"top"
,
label
:
"Date"
,
//tickFormat: "d",
//ticks: d3.ticks(...d3.extent(data, (d) => d.Month), 10),
//tickFormat: Plot.formatMonth("en", "short")
}
,
y
:
{
label
:
"Episode"
,
label
:
null
}
,
color
:
{
type
:
"linear"
,
scheme
:
"PiYG"
}
,
marks
:
[
Plot
.
cell
(
data
,
{
x
:
(
d
)
=>
d
.
Month
,
y
:
"National Inflation Rate"
,
fill
:
"CPI"
,
inset
:
0.5
}
)
,
]
}
)
Insert cell
Plot
.
plot
(
{
padding
:
0
,
marginLeft
:
300
,
round
:
false
,
label
:
null
,
x
:
{
axis
:
"top"
}
,
marks
:
[
Plot
.
barX
(
data
,
{
x
:
"Month"
,
y
:
"National Inflation Rate"
,
interval
:
"month"
,
inset
:
0.5
,
fill
:
"CPI"
,
title
:
"CPI"
,
tip
:
"xy"
}
)
,
]
}
)
Insert cell
simpsons
=
FileAttachment
(
"simpsons.csv"
)
.
csv
(
{
typed
:
true
}
)
Insert cell
data
=
FileAttachment
(
"index3 (18).csv"
)
.
csv
(
{
typed
:
true
}
)
Insert cell
data
.
forEach
(
d
=>
{
const
year
=
d
.
Month
.
slice
(
0
,
4
)
;
const
month
=
d
.
Month
.
slice
(
5
,
7
)
;
d
.
Month
=
new
Date
(
`${
year
}-${
month
}-01`
)
;
d
[
"CPI"
]
=
+
d
[
"CPI"
]
;
}
)
;
Insert cell
d3
.
ticks
(
...
d3
.
extent
(
data
,
(
d
)
=>
d
.
Month
)
,
2
)
Insert cell
Plot
.
plot
(
{
x
:
{
ticks
:
d3
.
ticks
(
...
d3
.
extent
(
hadcrut
,
(
d
)
=>
d
.
year
)
,
10
)
,
tickFormat
:
"d"
,
interval
:
1
,
// recommended in case of missing data
label
:
null
}
,
color
:
{
scheme
:
"BuRd"
}
,
marks
:
[
Plot
.
cell
(
hadcrut
,
{
x
:
"year"
,
fill
:
"anomaly"
}
)
]
}
)
Insert cell
hadcrut
=
(
await
FileAttachment
(
"hadcrut-annual.txt"
)
.
text
(
)
)
.
trim
(
)
.
split
(
/\n/g
)
// split into lines
.
map
(
line
=>
line
.
split
(
/\s+/g
)
)
// split each line into fields
.
map
(
(
[
year
,
anomaly
]
)
=>
(
{
// extract the year and median anomaly
year
:
+
year
,
// as a number
anomaly
:
+
anomaly
}
)
)
Insert cell
d3
.
ticks
(
...
d3
.
extent
(
hadcrut
,
(
d
)
=>
d
.
year
)
,
10
)
Insert cell
axis
(
d3
.
scaleTime
(
)
)
.
ticks
(
20
)
.
render
(
)
Insert cell
One platform
to build and deploy the best data apps
Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Try it for free
Learn more
Compare fork
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
simpsons
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
hadcrut
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