|
103 | 103 | >
|
104 | 104 | > **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.
|
105 | 105 |
|
| 106 | +````@example plots |
| 107 | +using GLMakie |
| 108 | +using AlgebraOfGraphics |
| 109 | +GLMakie.activate!() |
| 110 | +# let's continue using the cmip6 dataset |
| 111 | +c = g["tas"] |
| 112 | +```` |
106 | 113 |
|
107 | 114 |
|
| 115 | +````@example plots |
| 116 | +# let's continue using the cmip6 dataset |
| 117 | +c = g["tas"] |
| 118 | +```` |
| 119 | + |
| 120 | +and let's focus on the first time step: |
| 121 | + |
| 122 | +````@example plots |
| 123 | +dim_data = c[time=1][:,:] # read into memory first! |
| 124 | +plt = data(dim_data) * mapping(:lon, :lat; color=:value) * visual(Scatter, marker=:rect) |
| 125 | +draw(plt) |
| 126 | +```` |
| 127 | + |
| 128 | +and now plot |
| 129 | + |
| 130 | +````@example plots |
| 131 | +data(dim_data) * mapping(:lon, :lat; color=:value) * visual(Scatter) |> draw |
| 132 | +```` |
| 133 | + |
| 134 | +set other attributes |
| 135 | + |
| 136 | +````@example plots |
| 137 | +plt = data(dim_data) * mapping(:lon, :lat; color=:value) |
| 138 | +draw(plt * visual(Scatter, marker=:rect), scales(Color = (; colormap = :plasma)); |
| 139 | + axis = (width = 600, height = 400, limits=(0, 360, -90, 90))) |
| 140 | +```` |
| 141 | + |
| 142 | +## Faceting |
| 143 | + |
| 144 | +For this let's consider more time steps from our dataset: |
| 145 | + |
| 146 | +````@example plots |
| 147 | +using Dates |
| 148 | +dim_time = c[time=DateTime("2015-01-01") .. DateTime("2015-01-01T21:00:00")] # subset 7 t steps |
| 149 | +```` |
| 150 | + |
| 151 | +````@example plots |
| 152 | +dim_time = dim_time[:,:,:]; # read into memory first! |
| 153 | +nothing # hide |
| 154 | +```` |
| 155 | + |
| 156 | +````@example plots |
| 157 | +plt = data(dim_time) * mapping(:lon, :lat; color = :value, layout = :time => nonnumeric) |
| 158 | +draw(plt * visual(Scatter, marker=:rect)) |
| 159 | +```` |
| 160 | + |
| 161 | +again, let's add some additional attributes |
| 162 | + |
| 163 | +````@example plots |
| 164 | +plt = data(dim_time) * mapping(:lon, :lat; color = :value, layout = :time => nonnumeric) |
| 165 | +draw(plt * visual(Scatter, marker=:rect), scales(Color = (; colormap = :magma)); |
| 166 | + axis = (; limits=(0, 360, -90, 90)), |
| 167 | + figure=(; size=(900,600))) |
| 168 | +```` |
0 commit comments