Platform
Resources
Pricing
Sign in
Get started
Mike Freeman
Data visualization software enginner: working to make visualization more accessible, equitable, and impactful.
Workspace
Fork
Published
By
Mike Freeman
Edited
May 4, 2021
Insert cell
Insert cell
Insert cell
// Show a table of the data
Table
(
data
)
Insert cell
Insert cell
// Create a horizontal bar chart showing the number of cases for each college
Plot
.
barX
(
data
,
{
x
:
"cases_2021"
,
y
:
"college"
}
)
.
plot
(
{
y
:
{
domain
:
top_colleges
,
label
:
""
}
,
marginLeft
:
160
}
)
Insert cell
Insert cell
// Create a horizontal bar chart showing the total number of cases for each state
Plot
.
barX
(
data
,
{
x
:
"cases_2021"
,
y
:
"state"
,
fill
:
"college"
}
)
.
plot
(
{
y
:
{
domain
:
state_order
.
map
(
(
d
)
=>
d
.
state
)
}
,
marginLeft
:
160
}
)
Insert cell
Insert cell
Insert cell
// Create a scatter plot comparing the 2021 cases to the total cases for a given state
scatter
=
Plot
.
text
(
data
.
filter
(
d
=>
d
.
state
===
state
)
,
{
x
:
"cases"
,
y
:
"cases_2021"
,
text
:
"college"
}
)
.
plot
(
)
Insert cell
Insert cell
// Get the top 10 colleges in 2021
top_colleges
=
tidy
(
data
,
sliceMax
(
10
,
"cases_2021"
)
)
.
map
(
(
d
)
=>
d
.
college
)
Insert cell
// Get a list of states / territories
states
=
tidy
(
data
,
distinct
(
"state"
)
)
.
map
(
d
=>
d
.
state
)
Insert cell
// Sort the states by the total number of cases in 2021
state_order
=
tidy
(
data
,
groupBy
(
"state"
,
[
summarize
(
{
cases_2021
:
sum
(
"cases_2021"
)
}
)
]
)
,
arrange
(
desc
(
"cases_2021"
)
)
)
Insert cell
Insert cell
data
=
d3
.
csv
(
"https://raw.githubusercontent.com/nytimes/covid-19-data/master/colleges/colleges.csv"
,
d3
.
autoType
)
Insert cell
d3
=
require
(
"d3"
)
Insert cell
import
{
Table
,
Select
}
from
"@observablehq/inputs"
Insert cell
Plot
=
require
(
"@observablehq/plot@0.1.0/"
)
Insert cell
import
{
tidy
,
arrange
,
filter
,
desc
,
summarize
,
groupBy
,
sum
,
distinct
,
sliceMax
}
from
"@pbeshai/tidyjs"
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
Add comment
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
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
state
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
scatter
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
top_colleges
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
states
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
state_order
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
data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
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
Plot
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