-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.jl
257 lines (203 loc) · 6.6 KB
/
example.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
### A Pluto.jl notebook ###
# v0.20.4
using Markdown
using InteractiveUtils
# ╔═╡ 06be8ac3-fa55-449d-ad3f-8162bd36c6b7
begin
import Pkg
Pkg.activate()
end
# ╔═╡ b3656548-3be2-47ed-898e-3634003eee0b
using Revise, ObservablePlotExperiment
# ╔═╡ 76ec430d-3c01-4545-8be3-e82528257c33
using CSV, DataFrames
# ╔═╡ b5ab10a0-d0c1-477e-8985-8cfbbc38fc6b
using Dates
# ╔═╡ 9b80c3d6-ed15-499f-806b-6fa1091c417a
using HypertextLiteral
# ╔═╡ b28904fd-8cc9-41fc-9806-748ede4cc6cd
md"""
Combining with Plot:
"""
# ╔═╡ 7a19ed10-00f8-452d-8a73-a6f810adffbd
md"""
Options:
"""
# ╔═╡ 5f744aee-dadd-4b04-a067-7a102a36ae83
md"""
# Getting the data
"""
# ╔═╡ 464672aa-cc48-11ef-3173-9bb6140273d2
url1 = "https://gml.noaa.gov/webdata/ccgg/trends/co2/co2_mm_mlo.csv"
# ╔═╡ 55d66238-68c1-4c7a-8159-f411fa663260
url2 = "https://gml.noaa.gov/webdata/ccgg/trends/co2/co2_daily_mlo.csv"
# ╔═╡ 1e735495-ef76-433a-b3a4-dd787fa4f669
Text(read(download(url2), String))
# ╔═╡ 3525308c-a7d7-4373-8826-f5a46a21c42a
d = CSV.read(download(url1), DataFrame; comment="#")
# ╔═╡ 063d8376-2c3b-4d74-abe8-582fe6bd9d1d
d2 = CSV.read(download(url2), DataFrame; comment="#", header=0)
# ╔═╡ 1cfc7eb7-a190-4072-9c3a-f3abac8befa7
# ╔═╡ cdfa1d2a-baa0-4831-a6b1-69385efa8eb3
dates = [Date(x[1], x[2], x[3]) for x in eachrow(d2)]
# ╔═╡ 7ea7d253-7410-44d8-bbda-3fe6a20888ef
Base.PkgId(Base.UUID("ade2ca70-3891-5945-98fb-dc099432e06a"), "Dates")
# ╔═╡ 5b695b6b-e818-4276-9618-c79e8f208e82
Base.loaded_modules[Base.PkgId(Base.UUID("ade2ca70-3891-5945-98fb-dc099432e06a"), "Dates")]
# ╔═╡ 97d30320-ff55-4d2c-90bc-935ca233f1cc
tidyzip(x=[1,2,3], y=[6,7])
# ╔═╡ 3e91edb7-3a29-4288-b8e0-826296e06d20
vals = [x[5] for x in eachrow(d2)]
# ╔═╡ 383c54e5-9315-4b52-b77b-43f73dc252dd
cell(zip(dates[1:400], vals[1:400]);
x=@jsl("d => d[0].getUTCDate()"),
y=@jsl("d => d[0].getUTCMonth()"),
fy=@jsl("d => d[0].getUTCFullYear()"),
fill=@jsl("d => d[1]"),
)
# ╔═╡ 1a8a376d-6a66-4c77-b5f5-5929a1e330a5
cell(tidyzip(
CO₂=vals[1:400],
month=month.(dates[1:400]),
day=dayofmonth.(dates[1:400]),
year=year.(dates[1:400])
); fill="CO₂", x="day", y="month", fy="year")
# ╔═╡ 52ddb495-724a-4572-aa55-0f490ac77c40
cell(nothing;
fill=vals[1:2000],
x=dayofmonth.(dates[1:2000]),
y=month.(dates[1:2000]),
fy=year.(dates[1:2000]),
).plot(x=(label="asdf",))
# ╔═╡ 0c89c8ad-7ee9-4dcf-8bc3-f3a1bf3f73a4
# line(dates, vals)
# ╔═╡ 4c9a553c-2319-4d22-9afb-5c35232e4c29
vals
# ╔═╡ e7e02789-bc11-449c-863a-86a604bfff00
plot(
line(
zip(dates[1:70],vals[1:70]);
marker=true,
curve= "catmull-rom",
);
x=(label="asdf",),
y =(
label="CO2 ppm",
transform=@jsl("x => x * 2"),
),
)
# ╔═╡ d349e5b1-6be3-4399-af82-3322529b20a5
plot()
# ╔═╡ e76769de-3fa6-46c5-b91f-a86e9045c7e6
(x=(label="index",), )|> typeof
# ╔═╡ 37c1b129-f631-472a-bba8-9e4766d5739f
md"""
IDEA! when you pass in props that observablehq does not know but they exist in Plots/makie then we can show hints
like markersize, xlabel, xlims
"""
# ╔═╡ 9a4b7cd3-c436-48ca-9d61-214f76b217fe
plot(
line(zip(dates[1:100], vals[1:100]); curve="catmull-rom",),
dot(zip(dates[1:100], vals[1:100]); tip=true);
y=(
grid=true,
transform=@jsl("x => x*2"),
),
)
# ╔═╡ 468ca161-92f6-4f51-b1fb-7d3a14ca47b4
lineY(vals; tip=true)
# ╔═╡ c8224122-8307-46e4-85c9-82ed6591ba5b
lineY(vals; x=smart_embed_data(dates))
# ╔═╡ 9125e779-2903-40bc-b2f0-57864f4defd2
# ╔═╡ 32c9e066-d734-4226-bcf9-c8f2e9aa01e0
dot(zip(dates, vals))
# ╔═╡ eaea893c-2d29-45fb-b63f-b866b9ca9b9f
z = randn(101)
# ╔═╡ 654fe84c-783f-421e-9680-85ab2435f5b6
data = z[1:100] .+ z[2:101] .+ 2
# ╔═╡ d6aed7bc-972d-4916-915d-2c6adddc9768
data
# ╔═╡ 04152403-abde-4b8f-83ad-1b35bc374d32
dot(enumerate(data))
# ╔═╡ 36a7cd4f-e957-45ab-951e-1ee90a9ad333
lineY(data)
# ╔═╡ 0bffc169-cbb4-42e2-ba6c-8dc35fa606e7
lineX(data)
# ╔═╡ c05bb2f6-7a7c-4e55-88fe-18b803b339c0
plot(
lineY(data),
dot(enumerate(data))
)
# ╔═╡ b3fe231e-2656-4e97-b026-977e6b854125
plot(
(
lineY(data .+ i)
for i in 1:10
)...,
)
# ╔═╡ 5872fbe3-702b-4ebf-8cc9-ec9322c4aa7b
peaks = map(enumerate(data)) do (i,x)
left = data[max(begin,i-1)]
right = data[min(end,i+1)]
left < x > right
end
# ╔═╡ 6a13b7fe-f12c-4518-a1df-9bbd55174765
plot(
# dot(enumerate(data); ),
lineY(data; tip=false, marker=true),
text(enumerate(data);
lineAnchor="bottom",
dy=-6,
filter=peaks,
),
x=(label="index"),
# y=(type="log",),
height=200,
)
# ╔═╡ 1576f9f3-74d0-4c70-8e33-8a54ec79e4f8
dotY(data; x=eachindex(data))
# ╔═╡ Cell order:
# ╠═d6aed7bc-972d-4916-915d-2c6adddc9768
# ╠═04152403-abde-4b8f-83ad-1b35bc374d32
# ╠═36a7cd4f-e957-45ab-951e-1ee90a9ad333
# ╠═0bffc169-cbb4-42e2-ba6c-8dc35fa606e7
# ╟─b28904fd-8cc9-41fc-9806-748ede4cc6cd
# ╠═c05bb2f6-7a7c-4e55-88fe-18b803b339c0
# ╠═b3fe231e-2656-4e97-b026-977e6b854125
# ╟─7a19ed10-00f8-452d-8a73-a6f810adffbd
# ╟─5f744aee-dadd-4b04-a067-7a102a36ae83
# ╠═06be8ac3-fa55-449d-ad3f-8162bd36c6b7
# ╠═464672aa-cc48-11ef-3173-9bb6140273d2
# ╠═55d66238-68c1-4c7a-8159-f411fa663260
# ╠═1e735495-ef76-433a-b3a4-dd787fa4f669
# ╠═76ec430d-3c01-4545-8be3-e82528257c33
# ╠═3525308c-a7d7-4373-8826-f5a46a21c42a
# ╠═063d8376-2c3b-4d74-abe8-582fe6bd9d1d
# ╠═1cfc7eb7-a190-4072-9c3a-f3abac8befa7
# ╠═cdfa1d2a-baa0-4831-a6b1-69385efa8eb3
# ╠═383c54e5-9315-4b52-b77b-43f73dc252dd
# ╠═7ea7d253-7410-44d8-bbda-3fe6a20888ef
# ╠═5b695b6b-e818-4276-9618-c79e8f208e82
# ╠═1a8a376d-6a66-4c77-b5f5-5929a1e330a5
# ╠═52ddb495-724a-4572-aa55-0f490ac77c40
# ╠═97d30320-ff55-4d2c-90bc-935ca233f1cc
# ╠═3e91edb7-3a29-4288-b8e0-826296e06d20
# ╠═0c89c8ad-7ee9-4dcf-8bc3-f3a1bf3f73a4
# ╠═b5ab10a0-d0c1-477e-8985-8cfbbc38fc6b
# ╠═9b80c3d6-ed15-499f-806b-6fa1091c417a
# ╠═b3656548-3be2-47ed-898e-3634003eee0b
# ╠═4c9a553c-2319-4d22-9afb-5c35232e4c29
# ╠═e7e02789-bc11-449c-863a-86a604bfff00
# ╠═d349e5b1-6be3-4399-af82-3322529b20a5
# ╠═6a13b7fe-f12c-4518-a1df-9bbd55174765
# ╠═e76769de-3fa6-46c5-b91f-a86e9045c7e6
# ╠═5872fbe3-702b-4ebf-8cc9-ec9322c4aa7b
# ╠═37c1b129-f631-472a-bba8-9e4766d5739f
# ╠═9a4b7cd3-c436-48ca-9d61-214f76b217fe
# ╠═468ca161-92f6-4f51-b1fb-7d3a14ca47b4
# ╠═c8224122-8307-46e4-85c9-82ed6591ba5b
# ╠═9125e779-2903-40bc-b2f0-57864f4defd2
# ╠═32c9e066-d734-4226-bcf9-c8f2e9aa01e0
# ╠═eaea893c-2d29-45fb-b63f-b866b9ca9b9f
# ╠═654fe84c-783f-421e-9680-85ab2435f5b6
# ╠═1576f9f3-74d0-4c70-8e33-8a54ec79e4f8