Public
Edited
May 19, 2023
Insert cell
Insert cell
Insert cell
df = FileAttachment("student_teacher_ratio.csv").csv()
Insert cell
Insert cell
Insert cell
import {seattleWeatherTyped} from '@jonfroehlich/intro-to-vega-lite'
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = full_data.filter(d=>d.media_type!='Social Media')
Insert cell
dot_plot(data)
Insert cell
function dot_plot(data){
return Plot.plot({
marginLeft:200,
x:{domain:[d3.min(data.map(d=>d.rep_diff))*1.1, d3.max(data.map(d=>d.dem_diff))*1.1], axis: "top",grid:true},
y:{grid:true},
color:{domain:['Total', 'Dem', 'Rep'], range:['#9498A2', '#163BA6', '#B22719'], legend:true},
width:800,
marks:[
Plot.ruleX([0]),
Plot.ruleY(data, {x1:'dem_diff', x2:'rep_diff', y:'name', strokeWidth:5, opacity:0.2}),
Plot.dot(data, {x:'total_diff', y:'name', fill:'#9498A2', r:5, sort:{y:'x', reverse:true}}),
Plot.dot(data, {x:'dem_diff', y:'name', fill:'#163BA6', r:5, sort:{y:'x', reverse:true}}),
Plot.dot(data, {x:'rep_diff', y:'name', fill:'#B22719', r:5, sort:{y:'x', reverse:true}})
]
})
}

Insert cell
social_data = full_data.filter(d=>d.media_type=='Social Media')
Insert cell
dot_plot(social_data)
Insert cell
d3.min(data.map(d=>d.rep_diff))*1.1
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