Public
Edited
Dec 28, 2022
Insert cell
Insert cell
ts032_cymreigrwyd@1.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
ydata = FileAttachment("ts032_lsoa_cymreigwyd.csv").csv()
Insert cell
newidynnau =ydata.columns

Insert cell
dewis =newidynnau.slice(4,13)
Insert cell
awdurdodsgil = dewis.flatMap(newidyn => ydata.map(d => ({awdurdod: d.LocalAuthority_ItemName_WEL, lsoa: d.daearyddiaeth, newidyn, pobl: d[newidyn]}))) // pivot
Insert cell
awdurdodcanran = ydata.map(d => [{awdurdod: d.LocalAuthority_ItemName_WEL, lsoa: d.daearyddiaeth, canran: d.cnrnSiarad/100, siaradwyr: d.cyfanswm_siarad}])
Insert cell
dewiswyd1 = awdurdodcanran.flatMap(d =>d).filter(function(d) {return d.awdurdod==detholwyd})

Insert cell
viewof awdurdod = Inputs.select(awdurdodsgil.map(d => d.awdurdod), {unique:true, label: "Dewis gategori:", width:450, style: {fontSize: 25}})
Insert cell
plotSiarad=Plot.plot({marginLeft: 200, marginTop:60,
width,
x: {axis: "top", tickFormat: ".1f", percent: true, label: "% yn gallu siarad Cymraeg"},
y: {label:"Awdurdod lleol a chod LSOA"},
type: "identity",
style: {fontSize:12},
grid: true,
marks: [ Plot.frame(),
Plot.dot(dewiswyd1, {
y: "lsoa",
x: "canran",
r: "siaradwyr",
title: (d) =>
`${Math.round(100*d.canran)} %`,
fill: "lightgreen",
sort: {y: "x", reverse: true}
}),
]
})
Insert cell
viewof sgil = Inputs.select(awdurdodsgil.map(d => d.newidyn), {unique:true, label: "Dewis gategori:", width:450, style: {fontSize: 25}})

Insert cell
sgil
Insert cell
detholwyd = (awdurdod)
Insert cell
dewiswyd2 = awdurdodsgil.filter(function(d) {return d.awdurdod == awdurdod & d.newidyn==sgil})
Insert cell
plotSgil=Plot.plot({marginLeft: 200, marginTop:60,
width,
x: {axis: "top", tickFormat: "s",label: "Poblogaeth"},
y: {label:"Awdurdod lleol"},
color: {scheme: "category10", domain: dewis},
style: {fontSize:12},
marks: [
Plot.barX(dewiswyd2, {
y: "lsoa",
x: "pobl",
title: (d) =>
`${d.pobl} â'r sgil:`+`${d.newidyn}`,
fill: "newidyn",
sort: {y: "x", reverse: true}
}),
Plot.ruleX([0])
],
tooltip: {
fill: "purple"
}
})
Insert cell
dewiswyd3 = awdurdodsgil.filter(function(d) {return d.awdurdod == awdurdod})
Insert cell
import {Plot} from "@mkfreeman/plot-tooltip"
Insert cell
plotSgil.legend("color",{label:"Sgil",swatchSize:20, columns:2,style:{fontSize:"20px"}})
Insert cell
plotCyfan=Plot.plot({marginLeft: 200, marginTop:60,width,
x: {axis: "top", tickFormat: "s",label: "Poblogaeth"},
y: {label:"Ardal gynnyrch ehangach haen isaf"},
color: {scheme: "category10", domain: dewis},
style: {fontSize:12},
marks: [
Plot.barX(dewiswyd3, {
y: "lsoa",
x: "pobl",
title: (d) =>
`${d.pobl} â'r sgil:`+`${d.newidyn}`,
fill: "newidyn",
sort: {y: "x", reverse: true}
}),
Plot.ruleX([0])
],
tooltip: {
fill: "purple"
}
})

Insert cell
import {StackedBarChart} from "@d3/stacked-normalized-horizontal-bar"

Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

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