Platform
Resources
Pricing
Sign in
Get started
LilyLi
Workspace
Fork
Public
By
LilyLi
Edited
Apr 12, 2023
Fork of
Plot: Histogram
•
1 fork
2
Insert cell
2
Insert cell
Insert cell
Insert cell
911-daily-dispatch-count-by-agency.csv
Filter
Columns
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
rawData
=
FileAttachment
(
"911-daily-dispatch-count-by-agency.csv"
)
.
csv
(
{
typed
:
true
}
)
;
// notes:
// Boston Police Department (BPD)
// Boston Fire Department (BFD)
// Emergency Medical Services (EMS)
Insert cell
Insert cell
// define a set called years for later use
// => it should contain all the years mentioned in the dataset
years
=
new
Set
(
)
;
Insert cell
// get all the years in dataset
rawData
.
forEach
(
obj
=>
years
.
add
(
obj
.
Year
)
)
;
Insert cell
// have a look at years set
years
Insert cell
callTypes
=
[
'BPD'
,
'BFD'
,
'EMS'
]
;
Insert cell
data
=
[
]
Insert cell
2
rawData
.
forEach
(
d
=>
{
// convert Year+Month to a number used in x axis
const
time
=
d
[
'Year'
]
+
(
1
/
12
)
*
d
[
'Month'
]
// for each type of call, we need push the object for certain times
callTypes
.
forEach
(
callType
=>
{
const
number
=
d
[
callType
]
;
for
(
let
i
=
0
;
i
<
number
;
i
++
)
{
data
.
push
(
{
year
:
time
,
type
:
callType
}
)
}
}
)
}
)
Insert cell
// have a look at the data
data
Insert cell
Insert cell
Plot
.
plot
(
{
y
:
{
grid
:
true
}
,
marginLeft
:
50
,
marginBottom
:
50
,
marginTop
:
50
,
color
:
{
legend
:
true
,
}
,
marks
:
[
Plot
.
rectY
(
data
,
Plot
.
binX
(
{
y
:
"count"
}
,
{
x
:
"year"
,
thresholds
:
d3
.
range
(
2010
,
2016
,
1
)
,
fill
:
"type"
}
)
)
,
Plot
.
ruleY
(
[
0
]
)
]
}
)
Insert cell
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
Show 2 comments
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
dailyDispatchCountByAgency
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
File attachments
penguins.csv
CSV
911-daily-dispatch-count-by-agency.csv
CSV
Databases
Filter
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
rawData
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
years
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
callTypes
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
Show 2 comments
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
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