NOAA CO2

마우나로아의 NOAA 월별 CO2 농도 데이터 CSV를 읽고 그래프로 그립니다.

data = {
  const co2data = await FileAttachment("co2_mm.csv")
    .csv({ typed: true });
  return co2data.map(d => { 
    d["decimal date"] = Number(d["decimal date"]);
    d.average = Number(d.average); 
    return d; 
  });
}
Plot.plot({
  marks: [
    Plot.line(data, 
      { x: "decimal date", y: "average"}, 
      { stroke: "black" }
    )
  ]
})

같은 데이터를 R로 읽어 그룹화와 요약을 수행한 뒤 ojs_define으로 사용할 수 있게 만듭니다.

library(readr)
library(dplyr)

co2 = read_csv("co2_mm.csv")  %>% 
  group_by(year) %>% 
  summarize(max = max(average))

ojs_define(co2data = co2)

이제 요약된 데이터를 그립니다.

Plot.plot({
  marks: [
    Plot.line(transpose(co2data), 
      {x: "year", y: "max"}, 
      { stroke: "black" }
    )
  ]}
)