Platform
Resources
Pricing
Sign in
Get started
Calvin Zhong
Workspace
Fork
Public
By
Calvin Zhong
Edited
Feb 20, 2023
Fork of
Week 3 - Introduction to Exploratory Data Visualization
1
Insert cell
Insert cell
Insert cell
Insert cell
NYCHA_Development_Data_Book.csv
Filter
Columns
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
Insert cell
Insert cell
Insert cell
url
=
"https://data.cityofnewyork.us/resource/evjd-dqpz.csv"
Insert cell
nycha_fetched_data
=
d3
.
csv
(
url
,
d3
.
autoType
)
Insert cell
Insert cell
// using an index to select an item from an array
nycha_fetched_data
[
0
]
Insert cell
// this is like extracting a column from the data
nycha_fetched_data
.
map
(
(
d
)
=>
d
.
development
)
Insert cell
// calculate the minimum of a column
d3
.
min
(
nycha_fetched_data
,
(
d
)
=>
d
.
total_number_of_apartments
)
Insert cell
// calculate the minimum and maximum of a column
d3
.
extent
(
nycha_fetched_data
,
(
d
)
=>
d
.
total_population
)
Insert cell
// get a sample of the data
sample
=
nycha_fetched_data
.
filter
(
(
d
)
=>
d
.
total_population
>
400
)
Insert cell
Insert cell
Insert cell
Insert cell
Number
(
nycha_fetched_data
[
0
]
.
avg_monthly_gross_rent
.
replace
(
/[^0-9.-]+/g
,
""
)
)
Insert cell
Insert cell
import
{
tidy
,
mutate
,
arrange
,
desc
}
from
"@pbeshai/tidyjs"
Insert cell
nycha_clean_data
=
tidy
(
nycha_fetched_data
,
// 1. Cast Monthly Gross Rent as Numbers
mutate
(
{
avg_monthly_gross_rent
:
(
d
)
=>
{
if
(
d
.
avg_monthly_gross_rent
!==
null
)
return
Number
(
d
.
avg_monthly_gross_rent
.
replace
(
/[^0-9.-]+/g
,
""
)
)
;
else
return
0
;
}
}
)
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Type your code here:
Insert cell
Insert cell
Insert cell
// your code here
Insert cell
Insert cell
Insert cell
Plot
.
dot
(
nycha_clean_data
,
{
x
:
(
d
)
=>
d
.
avg_monthly_gross_rent
/
d
.
avg_no_r_r_per_apartment
,
y
:
"total_number_of_apartments"
,
fill
:
"blue"
}
)
.
plot
(
)
Insert cell
Insert cell
Plot
.
dot
(
nycha_clean_data
,
{
x
:
(
d
)
=>
d
.
avg_monthly_gross_rent
/
d
.
avg_no_r_r_per_apartment
,
y
:
"total_number_of_apartments"
,
// This applies a function to interpolate the color values based on the rent/no. of rooms
fill
:
(
d
)
=>
d
.
avg_monthly_gross_rent
/
d
.
avg_no_r_r_per_apartment
}
)
.
plot
(
{
color
:
{
scheme
:
"reds"
}
}
)
Insert cell
Let's color the stroke of our dots according to whether the average gross rent is larger than $600:
Insert cell
Plot
.
dot
(
nycha_clean_data
,
{
x
:
(
d
)
=>
d
.
avg_monthly_gross_rent
/
d
.
avg_no_r_r_per_apartment
,
y
:
"total_number_of_apartments"
,
// This applies a function to interpolate the color values based on the rent/no. of rooms
fill
:
(
d
)
=>
d
.
avg_monthly_gross_rent
>
600
}
)
.
plot
(
{
color
:
{
range
:
[
"orange"
,
"steelblue"
]
}
}
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot
.
rect
(
nycha_clean_data
,
Plot
.
bin
(
{
fillOpacity
:
"count"
}
,
{
x
:
"avg_monthly_gross_rent"
,
y
:
"total_number_of_apartments"
,
// This applies a function to interpolate the color values based on the rent/no. of rooms
fill
:
(
d
)
=>
d
.
avg_monthly_gross_rent
>
600
}
)
)
.
plot
(
{
color
:
{
range
:
[
"orange"
,
"steelblue"
]
}
}
)
Insert cell
Insert cell
Plot
.
plot
(
{
marks
:
[
Plot
.
rectY
(
nycha_clean_data
,
Plot
.
binX
(
{
y
:
"count"
}
,
{
x
:
"avg_monthly_gross_rent"
}
)
)
,
Plot
.
ruleY
(
[
0
]
)
]
,
grid
:
true
,
color
:
{
legend
:
true
}
}
)
Insert cell
Insert cell
Plot
.
barX
(
nycha_clean_data
,
Plot
.
groupY
(
{
x
:
"mean"
}
,
{
x
:
"avg_monthly_gross_rent"
,
y
:
"borough"
,
sort
:
{
y
:
"x"
,
reverse
:
false
}
}
)
)
.
plot
(
{
marginLeft
:
120
}
)
Insert cell
Insert cell
Insert cell
Plot
.
plot
(
{
marks
:
[
Plot
.
rectY
(
nycha_clean_data
,
Plot
.
binX
(
{
y
:
"count"
}
,
{
x
:
"avg_monthly_gross_rent"
,
fill
:
"borough"
}
)
)
,
Plot
.
ruleY
(
[
0
]
)
]
,
x
:
{
label
:
"Average Monthly Gross Rent"
}
,
y
:
{
label
:
"Number of Developments"
}
,
grid
:
true
,
color
:
{
scheme
:
"cool"
,
legend
:
true
,
label
:
"Borough"
}
}
)
Insert cell
Insert cell
Insert cell
Insert cell
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
Compare fork
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
nycha_development_data_book
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
File attachments
NYCHA_Development_Data_Book.csv
CSV
Databases
Filter
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
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
url
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
nycha_fetched_data
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
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
sample
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
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
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
nycha_clean_data
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
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
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
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
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
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
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
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
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
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML