Here is Julia code to plot your own CO2 charts
using CSV, Plots, Downloads
# using MovingAverage
using EasyFit
println("Program carbon.jl")
# mainurl: https://gml.noaa.gov/ccgg/trends/data.html
url = "https://gml.noaa.gov/webdata/ccgg/trends/co2/co2_mm_mlo.csv"
f = CSV.File(Downloads.download(url),header=0;skipto=42);
yeararr = collect(Float64,f.Column3)
co2arr = collect(Float64,f.Column4)
# normco2arr = f.Column5
# Plot defaults
default(size=(800,600),linewidth=2.0)
plot(yeararr,co2arr,title="Historical CO2",
legend=false) |> display
#co2MAarr = moving_average(co2arr,12)
# Define our EasyFit.moveavg function
easymovingavg(arr,n)=(EasyFit.movavg(arr,n)).x
co2MAarr2 = easymovingavg(co2arr,12)
plot(yeararr,co2MAarr2,title="Annual Moving Average of CO2",
legend=false)
#plot!(yeararr,co2MAarr2) |> display
logco2MAarr = map(x->log(10,x),co2MAarr2)
plot(yeararr,logco2MAarr,title="Log10 of Annual Moving Average of CO2",
legend=false) |> display
plot(yeararr,co2arr)
plot!(yeararr,co2MAarr2,title="Annual CO2",
legend=false) |> display
# The 11th element of yeararr is the start of year 1959
# June of 1959 is (11+5)th element
# the average co2 value of 1959 is co2MAarr[(11+5)]
# Create array for average yearly co2 concentration
yearly1959co2arr = Float64[]
totalnumofyears = div((length(yeararr)-(11-1)),12)
let k # runs faster in local scope
for k = 0:(totalnumofyears - 1)
push!(yearly1959co2arr,co2MAarr2[(11+5)+(k*12)])
end
end
# Create array for yearly increment of co2
yearlyco2inc = similar(yearly1959co2arr)
let k # runs faster in local scope
for k = 1:length(yearlyco2inc)
if k == 1
yearlyco2inc[k] = 0.0
else
yearlyco2inc[k] = yearly1959co2arr[k] - yearly1959co2arr[k-1]
end
end
end
plot(1959:(1959+(totalnumofyears-1)),yearlyco2inc,
title="Annual increment of CO2",legend=false) |> display
yearly1960co2incarr = yearlyco2inc[2:end]
fiveyearincarr = Float64[]
let k
for k = 0:(div(length(yearly1960co2incarr),5)-1)
push!(fiveyearincarr,+(yearly1960co2incarr[(1+k*5):(5+k*5)]...))
end
end
bar(0:(div(length(yearly1960co2incarr),5)-1),fiveyearincarr,
yrange=(0.0,max(fiveyearincarr...) * 1.1),legend=false,
title="Five years CO2 increment") |> display