starting visualization journey
This commit is contained in:
1415
material/3_wed/linalg/Manifest.toml
Normal file
1415
material/3_wed/linalg/Manifest.toml
Normal file
File diff suppressed because it is too large
Load Diff
19
material/3_wed/linalg/Project.toml
Normal file
19
material/3_wed/linalg/Project.toml
Normal file
@@ -0,0 +1,19 @@
|
||||
[deps]
|
||||
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
|
||||
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
|
||||
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
|
||||
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
|
||||
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
|
||||
Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
|
||||
ClusterManagers = "34f1f09b-3a8b-5176-ab39-66d58a4d544e"
|
||||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
|
||||
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
|
||||
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
|
||||
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
|
||||
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
|
||||
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
|
||||
ParallelDataTransfer = "2dcacdae-9679-587a-88bb-8b444fb7085b"
|
||||
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
|
||||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
|
||||
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
|
||||
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
|
||||
1780
material/3_wed/vis/Manifest.toml
Normal file
1780
material/3_wed/vis/Manifest.toml
Normal file
File diff suppressed because it is too large
Load Diff
5
material/3_wed/vis/Project.toml
Normal file
5
material/3_wed/vis/Project.toml
Normal file
@@ -0,0 +1,5 @@
|
||||
[deps]
|
||||
AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67"
|
||||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
|
||||
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
|
||||
PalmerPenguins = "8b842266-38fa-440a-9b57-31493939ab85"
|
||||
132
material/3_wed/vis/handout.ipynb
Normal file
132
material/3_wed/vis/handout.ipynb
Normal file
@@ -0,0 +1,132 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
"\n",
|
||||
"jupyter: julia-1.9\n",
|
||||
"---"
|
||||
],
|
||||
"id": "d0dd3b54"
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Makie.jl\n",
|
||||
"\n",
|
||||
"## Backends\n",
|
||||
"Four backends:\n",
|
||||
"1. `CairoMakie` - SVG\n",
|
||||
"2. `GLMakie` - 2D/3D/fast interactivity\n",
|
||||
"3. `WGLMakie` - Same as GLMakie, but in browser\n",
|
||||
"4. `RPRMakie` - experimental raytracing\n",
|
||||
"\n",
|
||||
"I will use `GLMakie` or `CairoMakie`. To switch use `CairoMakie.activate!()`\n",
|
||||
"\n",
|
||||
"## Layouts for scientific figures\n",
|
||||
"\n",
|
||||
"# Pluto.jl for easy interactivity\n",
|
||||
"\n",
|
||||
"# Grammar of Graphics\n",
|
||||
"\n",
|
||||
"The grammar of graphics is a convenient way to build common explorative plots.\n",
|
||||
"\n",
|
||||
"For example:\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"#### For ggplot enthusiasts:\n",
|
||||
"You could use [TidierPlots.jl - a ggplot clone](https://github.com/TidierOrg/TidierPlots.jl)\n",
|
||||
"\n",
|
||||
"Check out the [../../../../cheatsheets/ggplotAOG.qmd]:\n",
|
||||
"\n",
|
||||
"## AlgebraOfGraphics.jl\n",
|
||||
"\n",
|
||||
"### Loading data"
|
||||
],
|
||||
"id": "0ca52ae6"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"using GLMakie # backend\n",
|
||||
"using AlgebraOfGraphics\n",
|
||||
"using PalmerPenguins, DataFrames # example dataset\n",
|
||||
"\n",
|
||||
"penguins = dropmissing(DataFrame(PalmerPenguins.load()))\n",
|
||||
"first(penguins, 6)"
|
||||
],
|
||||
"id": "56b4e637",
|
||||
"execution_count": null,
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"::: callout-note\n",
|
||||
"A `tidy dataframe` is a dataframe that follows these three rules:\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"1. Every column is a variable.\n",
|
||||
"2. Every row is an observation.\n",
|
||||
"3. Every cell is a single value.\n",
|
||||
"\n",
|
||||
"Tidy data make your visualization life much easier as you will see!\n",
|
||||
":::\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"### AoG basics\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"`data * mapping * visual`\n",
|
||||
"\n",
|
||||
"```julia\n",
|
||||
" vis_pen = data(penguins) * mapping(:bill_length_mm, :bill_depth_mm) * visual(Scatter) \n",
|
||||
" draw(vis_pen)\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"### Adding color\n",
|
||||
"\n",
|
||||
"```julia\n",
|
||||
"vis_pencolor = data(penguins) * mapping(:bill_length_mm, :bill_depth_mm, color = :species) * visual(Scatter)\n",
|
||||
"draw(vis_pencolor)\n",
|
||||
"\n",
|
||||
"```\n",
|
||||
"But that is a bit redundant, you can shortcut this, by reusing existing mappings / inputs:\n",
|
||||
"```julia\n",
|
||||
"vis_pencolor2 = vis_pen * mapping(color=:species)\n",
|
||||
"draw(vis_pencolor2)\n",
|
||||
"\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"### Why `Algebra`OfGraphics?\n",
|
||||
"\n",
|
||||
"Follows some algebraic rules of multiplying out sums\n",
|
||||
"\n",
|
||||
"`data * mapping * visual(Scatter+Lines)`\n",
|
||||
"\n",
|
||||
"```julia\n",
|
||||
"\n",
|
||||
" vis_pen = data(penguins) * mapping(:bill_length_mm, :bill_depth_mm) * visual(Scatter+Lines) \n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"### Faceting\n",
|
||||
"jl plt = penguin_bill * layers * mapping(color = :species, col = :sex)"
|
||||
],
|
||||
"id": "3ead8444"
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"name": "julia-1.8",
|
||||
"language": "julia",
|
||||
"display_name": "Julia 1.8.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
116
material/3_wed/vis/handout.qmd
Normal file
116
material/3_wed/vis/handout.qmd
Normal file
@@ -0,0 +1,116 @@
|
||||
---
|
||||
|
||||
jupyter: julia-1.9
|
||||
---
|
||||
# Makie.jl
|
||||
|
||||
## Backends
|
||||
Four backends:
|
||||
1. `CairoMakie` - SVG
|
||||
2. `GLMakie` - 2D/3D/fast interactivity
|
||||
3. `WGLMakie` - Same as GLMakie, but in browser
|
||||
4. `RPRMakie` - experimental raytracing
|
||||
|
||||
I will use `GLMakie` or `CairoMakie`. To switch use `CairoMakie.activate!()`
|
||||
|
||||
## Layouts for scientific figures
|
||||
|
||||
# Pluto.jl for easy interactivity
|
||||
|
||||
# Grammar of Graphics
|
||||
|
||||
The grammar of graphics is a convenient way to build common explorative plots.
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
#### For ggplot enthusiasts:
|
||||
You could use [TidierPlots.jl - a ggplot clone](https://github.com/TidierOrg/TidierPlots.jl)
|
||||
|
||||
Check out the [../../../../cheatsheets/ggplotAOG.qmd]:
|
||||
|
||||
## AlgebraOfGraphics.jl
|
||||
|
||||
### Loading data
|
||||
```{julia}
|
||||
using GLMakie # backend
|
||||
using AlgebraOfGraphics
|
||||
using PalmerPenguins, DataFrames # example dataset
|
||||
|
||||
penguins = dropmissing(DataFrame(PalmerPenguins.load()))
|
||||
first(penguins, 6)
|
||||
```
|
||||
|
||||
::: callout-note
|
||||
A `tidy dataframe` is a dataframe that follows these three rules:
|
||||
|
||||
|
||||
1. Every column is a variable.
|
||||
2. Every row is an observation.
|
||||
3. Every cell is a single value.
|
||||
|
||||
Tidy data make your visualization life much easier as you will see!
|
||||
:::
|
||||
|
||||
|
||||
### AoG basics
|
||||
|
||||
|
||||
`data * mapping * visual`
|
||||
|
||||
```{julia}
|
||||
vis_pen = data(penguins) * mapping(:bill_length_mm, :bill_depth_mm) * visual(Scatter)
|
||||
draw(vis_pen)
|
||||
```
|
||||
|
||||
### Adding color
|
||||
|
||||
```{julia}
|
||||
vis_pencolor = data(penguins) * mapping(:bill_length_mm, :bill_depth_mm, color = :species) * visual(Scatter)
|
||||
draw(vis_pencolor)
|
||||
|
||||
```
|
||||
But that is a bit redundant, you can shortcut this, by reusing existing mappings / inputs:
|
||||
```{julia}
|
||||
vis_pencolor2 = vis_pen * mapping(color=:species)
|
||||
draw(vis_pencolor2)
|
||||
|
||||
```
|
||||
|
||||
### Why `Algebra`OfGraphics?
|
||||
|
||||
Follows some algebraic rules of multiplying out sums
|
||||
|
||||
`data * mapping * (visual(Scatter)+visual(Lines))`
|
||||
|
||||
```{julia}
|
||||
|
||||
data(penguins) * mapping(:bill_length_mm, :bill_depth_mm) * (visual(Scatter)+visual(Lines)) |> draw
|
||||
```
|
||||
|
||||
### Faceting
|
||||
```{julia}
|
||||
data(penguins) * mapping(:bill_length_mm, :bill_depth_mm) * mapping(color = :species, col = :sex) |> draw
|
||||
|
||||
```
|
||||
```{julia}
|
||||
data(penguins) * mapping(:bill_length_mm, :bill_depth_mm) * mapping(color = :species, col = :sex,row=:body_mass_g => x-> x>3500) |> draw
|
||||
|
||||
```
|
||||
|
||||
### Linear & Non-linear summaries
|
||||
```{julia}
|
||||
data(penguins) * mapping(:bill_length_mm, :bill_depth_mm, color=:species) * (linear() + visual(Scatter)) |> draw
|
||||
```
|
||||
```{julia}
|
||||
data(penguins) * mapping(:bill_length_mm, :bill_depth_mm, color=:species) * (smooth() + visual(Scatter)) |> draw
|
||||
```
|
||||
|
||||
|
||||
# Interactivity
|
||||
|
||||
With Makie.jl, two ways of interactivity:
|
||||
|
||||
**Observables** - very general way, a little bit more verbose
|
||||
|
||||
**Pluto.jl Sliders** - very simple, need to redraw plot everytime^[it is technically possible t combine Pluto with Observables, but it is a bit buggy]
|
||||
Reference in New Issue
Block a user