Public
Edited
Jun 21
Insert cell
Insert cell
data = FileAttachment("Death_rates_for_suicide__by_sex__race__Hispanic_origin__and_age__United_States.csv").csv()
Insert cell
Insert cell
vl.markBar()
.data(data)
.transform(
vl.filter("datum.STUB_LABEL === 'Male: ' + select_race || datum.STUB_LABEL === 'Female: ' + select_race"),
vl.calculate("datum.STUB_LABEL === 'Male: ' + select_race ? 'Male' : 'Female'").as('Sex_Filter'),
vl.groupby('Sex_Filter')
.aggregate(vl.mean('ESTIMATE').as('Average_Suicide_Rate'))
)
.encode(
vl.y().fieldN('Sex_Filter').sort('x').axis({ title: 'Sex' }),
vl.x().fieldQ('Average_Suicide_Rate').scale({ domain: [0, 35] }).axis({ title: 'Average Suicide Rate (per 100,000)' }),
vl.color()
.fieldN('Sex_Filter')
.scale({ domain: ['Male', 'Female'], range: ['#c8b2db', '#e6d7f1'] })
.legend(null)
)
.params(
vl.param('select_race')
.value('White')
.bind({
input: 'select',
options: [
'White',
'Black or African American',
'American Indian or Alaska Native',
'Asian or Pacific Islander'
],
name: 'Race:'
})
)
.width(450)
.height(110)
.title('Average Suicide Rates by Sex and Race')
.render()
Insert cell
Insert cell
vl.markBar()
.data(data)
.transform(
vl.filter("datum.STUB_LABEL === 'Male: ' + select_race || datum.STUB_LABEL === 'Female: ' + select_race"),
vl.calculate("datum.STUB_LABEL === 'Male: ' + select_race ? 'Male' : 'Female'").as('Sex_Filter'),
vl.groupby('Sex_Filter')
.aggregate(vl.mean('ESTIMATE').as('Average_Suicide_Rate'))
)
.encode(
vl.y().fieldN('Sex_Filter').sort('-x').axis({ title: 'Sex' }),
vl.x().fieldQ('Average_Suicide_Rate').axis({ title: 'Average Suicide Rate (per 100,000)' }),
vl.color()
.fieldN('Sex_Filter')
.scale({ domain: ['Male', 'Female'], range: ['#ff5349', '#90EE90'] })
.legend(null),
vl.tooltip().fieldQ('Average_Suicide_Rate').format('.1f')
)
.params(
vl.param('select_race')
.value('White')
.bind({
input: 'select',
options: [
'White',
'Black or African American',
'American Indian or Alaska Native',
'Asian or Pacific Islander'
],
name: 'Race:'
})
)
.width(450)
.height(110)
.title('Disparities in Suicide by Sex and Race')
.render()
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.
Learn more