Skip to content

Commit efa6ad2

Browse files
authored
Merge pull request #484 from JuliaDataCubes/la/aog
aog documentation
2 parents fa39711 + aa255d4 commit efa6ad2

File tree

3 files changed

+141
-18
lines changed

3 files changed

+141
-18
lines changed

docs/Project.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[deps]
2+
AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67"
23
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
34
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
4-
Bonito = "824d6782-a2ef-11e9-3a09-e5662e0c26f8"
55
CFTime = "179af706-886a-5703-950a-314cd64e0468"
66
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
77
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
@@ -27,7 +27,6 @@ PlotUtils = "995b91a9-d308-5afd-9ec6-746e21dbc043"
2727
SkipNan = "aed68c70-c8b0-4309-8cd1-d392a74f991a"
2828
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2929
TimeSeries = "9e3dc215-6440-5c97-bce1-76c03772f85e"
30-
WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"
3130
WeightedOnlineStats = "bbac0a1f-7c9d-5672-960b-c6ca726e5d5d"
3231
YAXArrayBase = "90b8fcef-0c2d-428d-9c56-5f86629e9d14"
3332
YAXArrays = "c21b50f5-aa40-41ea-b809-c0f5e47bfa5c"

docs/src/UserGuide/group.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ end
6565
````
6666
:::
6767

68-
> [!IMPORTANT]
69-
> In what follows, note how we are referencing the _time_ dimension via _YAX.time_. This approach is used to avoid name clashes with _time_ (_Time_) from **Base** (**Dates**). For convenience, we have defined the **Dimensions** _time_ and _Time_ in **YAXArrays.jl**, which are only accessible when explicitly called.
68+
::: info
69+
70+
In what follows, note how we are referencing the time dimension via `YAX.time`. This approach is used to avoid name clashes with `time` (`Time`) from **Base** (**Dates**). For convenience, we have defined the **Dimensions** `time` and `Time` in **YAXArrays.jl**, which are only accessible when explicitly called.
71+
72+
:::
7073

7174
Now, we continue with the `groupby` operations as usual
7275

docs/src/tutorials/plottingmaps.md

Lines changed: 135 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ nothing # hide
2929
use lookup to get axis values
3030

3131
````@example plots
32-
lon = lookup(ct1_slice, :lon)
33-
lat = lookup(ct1_slice, :lat)
34-
data = ct1_slice.data[:,:];
32+
lon_d = lookup(ct1_slice, :lon)
33+
lat_d = lookup(ct1_slice, :lat)
34+
data_d = ct1_slice.data[:,:];
3535
nothing # hide
3636
````
3737

@@ -50,9 +50,9 @@ fig
5050
Some transformations
5151

5252
````@example plots
53-
δlon = (lon[2]-lon[1])/2
54-
nlon = lon .- 180 .+ δlon
55-
ndata = circshift(data, (192,1))
53+
δlon = (lon_d[2] - lon_d[1])/2
54+
nlon = lon_d .- 180 .+ δlon
55+
ndata = circshift(data_d, (192,1))
5656
nothing # hide
5757
````
5858

@@ -61,7 +61,7 @@ and add Coastlines with `GeoMakie.coastlines()`,
6161
````@example plots
6262
fig = Figure(;size=(1200,600))
6363
ax = GeoAxis(fig[1,1])
64-
surface!(ax, nlon, lat, ndata; colormap = :seaborn_icefire_gradient, shading=false)
64+
surface!(ax, nlon, lat_d, ndata; colormap = :seaborn_icefire_gradient, shading=false)
6565
cl=lines!(ax, GeoMakie.coastlines(), color = :white, linewidth=0.85)
6666
translate!(cl, 0, 0, 1000)
6767
fig
@@ -71,20 +71,18 @@ fig
7171
````@example plots
7272
fig = Figure(; size=(1200,600))
7373
ax = GeoAxis(fig[1,1]; dest = "+proj=moll")
74-
surface!(ax, nlon, lat, ndata; colormap = :seaborn_icefire_gradient, shading=false)
74+
surface!(ax, nlon, lat_d, ndata; colormap = :seaborn_icefire_gradient, shading=false)
7575
cl=lines!(ax, GeoMakie.coastlines(), color = :white, linewidth=0.85)
7676
translate!(cl, 0, 0, 1000)
7777
fig
7878
````
7979

8080
## 3D sphere plot
8181

82-
````julia
83-
using Bonito, WGLMakie
84-
Page(exportable=true, offline=true)
85-
86-
WGLMakie.activate!()
87-
Makie.inline!(true) # Make sure to inline plots into Documenter output!
82+
````@example plots
83+
using GLMakie
84+
using GLMakie.GeometryBasics
85+
GLMakie.activate!()
8886
8987
ds = replace(ndata, missing =>NaN)
9088
sphere = uv_normal_mesh(Tesselation(Sphere(Point3f(0), 1), 128))
@@ -98,4 +96,127 @@ rotate!(ax.scene, 2.5)
9896
fig
9997
````
10098

99+
## AlgebraOfGraphics.jl
100+
101+
::: info
102+
103+
From [DimensionalData docs](https://rafaqz.github.io/DimensionalData.jl/stable/plots#algebraofgraphics-jl) :
104+
105+
**AlgebraOfGraphics.jl** is a high-level plotting library built on top of `Makie.jl` that provides a declarative algebra for creating complex visualizations, similar to **ggplot2**'s "grammar of graphics" in R. It allows you to construct plots using algebraic operations like `*` and `+`, making it easy to create sophisticated graphics with minimal code.
106+
107+
:::
108+
109+
110+
````@example AoG
111+
using YAXArrays, Zarr, Dates
112+
using GLMakie
113+
using AlgebraOfGraphics
114+
using GLMakie.GeometryBasics
115+
GLMakie.activate!()
116+
````
117+
118+
let's continue using the cmip6 dataset
119+
120+
````@example AoG
121+
store ="gs://cmip6/CMIP6/ScenarioMIP/DKRZ/MPI-ESM1-2-HR/ssp585/r1i1p1f1/3hr/tas/gn/v20190710/"
122+
g = open_dataset(zopen(store, consolidated=true))
123+
c = g["tas"];
124+
nothing # hide
125+
````
126+
127+
and let's focus on the first time step:
128+
129+
````@example AoG
130+
dim_data = readcubedata(c[time=1]); # read into memory first!
131+
nothing # hide
132+
````
133+
134+
and now plot
135+
136+
````@example AoG
137+
data(dim_data) * mapping(:lon, :lat; color=:value) * visual(Scatter) |> draw
138+
````
139+
140+
::: warning
141+
142+
Note that we are using a `Scatter` type per point and not the `Heatmap` one. There are workarounds for this, albeit cumbersome, so for now, let's keep this simpler syntax in mind along with the current approach being used.
143+
144+
:::
145+
146+
set other attributes
147+
148+
````@example AoG
149+
plt = data(dim_data) * mapping(:lon, :lat; color=:value)
150+
draw(plt * visual(Scatter, marker=:rect), scales(Color = (; colormap = :plasma));
151+
axis = (width = 600, height = 400, limits=(0, 360, -90, 90)))
152+
````
153+
154+
### Faceting
155+
156+
For this let's consider more time steps from our dataset:
157+
158+
````@example AoG
159+
using Dates
160+
dim_time = c[time=DateTime("2015-01-01") .. DateTime("2015-01-01T21:00:00")] # subset 7 t steps
161+
````
162+
163+
````@example AoG
164+
dim_time = readcubedata(dim_time); # read into memory first!
165+
nothing # hide
166+
````
167+
168+
````@example AoG
169+
plt = data(dim_time) * mapping(:lon, :lat; color = :value, layout = :time => nonnumeric)
170+
draw(plt * visual(Scatter, marker=:rect))
171+
````
172+
173+
again, let's add some additional attributes
174+
175+
````@example AoG
176+
plt = data(dim_time) * mapping(:lon, :lat; color = :value, layout = :time => nonnumeric)
177+
draw(plt * visual(Scatter, marker=:rect), scales(Color = (; colormap = :magma));
178+
axis = (; limits=(0, 360, -90, 90)),
179+
figure=(; size=(900,600)))
180+
````
181+
182+
most [Makie plot functions](https://docs.makie.org/stable/reference/plots/overview) should work. See `lines` for example
183+
184+
````@example AoG
185+
plt = data(dim_data[lon=50..100]) * mapping(:lat, :value => "tas"; color=:value => "tas")
186+
draw(plt * visual(Lines); figure=(; size=(650,400)))
187+
````
188+
189+
or faceting them
190+
191+
````@example AoG
192+
plt = data(dim_data[lon=50..59]) * mapping(:lat, :value => "tas"; color=:value => "tas",
193+
layout = :lon => nonnumeric)
194+
draw(plt * visual(Lines); figure=(; size=(650,400)))
195+
````
196+
### Time series
197+
198+
For this, let's load a little bit more of time steps
199+
200+
````@example AoG
201+
dim_series = c[time=DateTime("2015-01-01") .. DateTime("2015-01-04"), lon = 150 .. 157, lat = 0..1] |> readcubedata
202+
````
203+
204+
and plot
205+
206+
````@example AoG
207+
plt = data(dim_series) * mapping(:time, :value => "tas"; color=:lon => nonnumeric)
208+
draw(plt * visual(ScatterLines), scales(Color = (; palette = :tableau_colorblind));
209+
figure=(; size=(800,400)))
210+
````
211+
212+
### Analysis
213+
214+
Basic statistical [analysis](https://aog.makie.org/stable/generated/analyses/) can also be done, for example:
215+
216+
````@example AoG
217+
specs = data(dim_data[lat=50..55]) * mapping(:lon, :value => "tas"; color=:lat => nonnumeric)
218+
specs *= (smooth() + visual(Scatter))
219+
draw(specs; figure=(; size=(700,400)))
220+
````
101221

222+
For more, visit [AlgebraOfGraphics.jl](https://aog.makie.org/stable/).

0 commit comments

Comments
 (0)