Published
Edited
Nov 22, 2020
Insert cell
md`# Additional Graphs for Final Project`
Insert cell
import {vl} from '@vega/vega-lite-api'
Insert cell
import {uniqueValid} from '@uwdata/data-utilities'
Insert cell
df_s2 = FileAttachment("df_s2@3.csv").csv()
Insert cell
races = uniqueValid(df_s2, d => d.RACETHMP)
Insert cell
races.unshift(races.pop())
Insert cell
races
Insert cell
vl.markBar()
.data(df_s2)
.encode(
vl.x().fieldN('GENDER').count(),
vl.y().fieldN('AGEGRP').title("Age Group").sort(["Ages 29 or younger ","Ages 30-34 ","Ages 35-39 ","Ages 40-44 ","Ages 45-49 ","Ages 50-54 ","Ages 55-59 ","Ages 60-64 ","Ages 65-69 ","Ages 70-75 ",]),
vl.color().fieldN('RACETHMP').legend(null),
vl.order().fieldN('RACETHMP').count().sort("descending"),
vl.tooltip().fieldN('RACETHMP'),
vl.column().fieldN('GENDER').title("PhD Recipients by Gender, Age and Race")
)
.render()
Insert cell
vl.markBar()
.data(df_s2)
.encode(
vl.x().fieldN('RACETHMP').count().title(null),
vl.y().fieldN('AGEGRP'),
vl.color().fieldN('RACETHMP').legend(null),
vl.tooltip().fieldN('RACETHMP'),
vl.column().fieldN('RACETHMP').sort("descending").title("PhD Recipients by Race")
)
.width(150)
.render()
Insert cell
//d_workalot = df_s2.filter(d => d.WKSYR === "Work 52 weeks per year " & d.HRSWKP === "Greater than 40 ")
Insert cell
d_workalot = FileAttachment("workalot_percent@1.csv").csv()
Insert cell
vl.markBar()
.data(d_workalot)
.encode(
vl.y().fieldQ('HRSWKP').title('Percentage of working individuals of category'),
vl.x().fieldN('GENDER').title(null),
vl.color().fieldN('GENDER').legend(null),
vl.tooltip().fieldQ('HRSWKP'),
vl.column().fieldN('AGEGRP').title("PhD Recipients working 52 weeks and >40 hrs/week")
)
.width(60)
.render()
Insert cell
smalldata = FileAttachment("448Bsmallgraph@5.csv").csv()
Insert cell
viewof chart1 = vl.markBar()
.data(smalldata)
.encode(
vl.y().fieldQ('n').title("Count of Records"),
vl.x().fieldN('GENDER').title(null),
vl.color().fieldN('GENDER').scale({domain: ['Male ', 'Female '], range: ['#17a596', '#e8505c']}).legend(null),
vl.tooltip().fieldQ('n'),
vl.column().fieldN('AGEGRP').title("Number of PhDs Who Had to Work Part Time due to Family Commitment")
).width(60)
.render()
//
Insert cell

viewof char2= vl.markBar()
.data(smalldata)
.encode(
vl.y().fieldQ('percent').title("Percent"),
vl.x().fieldN('GENDER').title(null),
vl.color().fieldN('GENDER').scale({domain: ['Male ', 'Female '], range: ['#17a596', '#e8505c']}).legend(null),
vl.tooltip().fieldQ('percent'),
vl.column().fieldN('AGEGRP').title("Percent of Each Age Group By Gender of PhDs Who Had to Work Part Time due to Family Commitment")
)
.width(60)
.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