Published unlisted
Edited
Jul 25, 2021
Insert cell
md `# Total Covid-19 Tests vs New CasesMalaysia`
Insert cell
url1 = "https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/cases_malaysia.csv"
Insert cell
url2 = "https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/tests_malaysia.csv"
Insert cell
newCase = await d3.csv(url1)
Insert cell
newCase2 = newCase.map( d => (
{
date: dateParser(d.date),
cases_new: d.cases_new
}
)
)
Insert cell
testNum = await d3.csv(url2)

Insert cell
testNum2 = testNum.map( d => (
{
date: dateParser(d.date),
pcr: parseInt(d[' pcr']),
rtk: parseInt(d[' rtk-ag']),
total: parseInt(d[' pcr']) + parseInt(d[' rtk-ag']),
}
)
)
.splice(52,547)
Insert cell
mergeData = _.merge(newCase2,testNum2 )
Insert cell
dateParser = d3.timeParse("%Y-%m-%d")
Insert cell
import {date} from "@jashkenas/inputs"

Insert cell
import {rangeSlider} from "@bumbeishvili/utils"
Insert cell
Inputs.table(mergeData2.data)
Insert cell
Changed in fork
Plot.plot({ grid: true, width:1200, height: 600, marginLeft: 80, marginBottom: 100, y: { label: "Total Tests", //transform: f => f / 1000, padding: 2 }, x: { label: "Date", nice: true, ticks: 5 }, marks: [ Plot.ruleY([0]),
-
Plot.barY(mergeData2.data , { x:"date", y: (d) => d.total / 10, fill:"#ff0000" } ), Plot.barY(mergeData2.data , { x:"date", y: "cases_new", fill:"#00ffff" } ),
+
Plot.areaY(mergeData2.data , { x:"date", y: (d) => d.total / 10, fill:"#ff0000", curve: "step" } ), Plot.areaY(mergeData2.data , { x:"date", y: "cases_new", fill:"#00ffff", curve: "step" } ),
//Plot.barY(mergeData2.data , { x:"date", y: (d) => (d.cases_new / d.total) * 100 , fill:"#ff0000" } ), ] })
Insert cell
Added in fork
Plot.plot({
grid: true,
width:1200,
height: 600,
marginLeft: 80,
marginBottom: 100,
y: {
label: "Total Tests",
//transform: f => f / 1000,
padding: 2
},
x: {
label: "Date",
nice: true,
ticks: 5
},
marks: [
Plot.ruleY([0]),
Plot.rectY(mergeData2.data , Plot.binX({y: "first"}, { x:"date", y: (d) => d.total / 10, fill:"#ff0000", curve: "step", thresholds: d3.utcDay } )),
Plot.rectY(mergeData2.data , Plot.binX({y: "first"}, { x:"date", y: "cases_new", fill:"#00ffff", thresholds: d3.utcDay } )),
//Plot.barY(mergeData2.data , { x:"date", y: (d) => (d.cases_new / d.total) * 100 , fill:"#ff0000" } ),
]
})
Insert cell
viewof mergeData2 = rangeSlider(mergeData, d=>d.date)
Insert cell
mergeData2
Insert cell