# Task 1: Visualize some statistic properties {#1}
## 1. Data
### Generate 500 normally distributed samples
::: callout-tip
You might want to make your results reproducible by fixing some seeds for the random generators. The two most common random generators used in julia are `Random.MersenneTwister` and `StableRNGs.StableRNG` - For this execrise I would recommend the latter (even though MersenneTwister is much more common to be used), thus run:
``` julia
using StableRNGs
randn(StableRNG(1),100)
```
to get 100 random numbers.
:::
Scale the random numbers to fullfill `std(x) ≈ 10`
### functionize it
Next wrap that code in a function `simulate` which takes two arguments, a random seed and the number of samples
## 2. cumulative mean
Calculate the cumulative mean of a single simulation. save it to a variable
Note that there is no `cummean` function, but clever element-wise division in combination with `cumsum` should lead you there - or you just use a loop :shrug:
Now for your first plot. Use a `scatter` plot^[after a `using CairoMakie`] to visualize the cummulative mean output, if you do not generate a `Figure()` + `ax = f[1,1] = Axis(f)` manually, you can get it back by the scatter call. `f,ax,s = scatter()`. This is helpful as we later want to extend the `Axis` and `Figure` with other plot elements
An easy way to call a function many times is to broadcast it on an array created e.g. via `1:1000` - you could also use `map` to do it, but I don't think it is as clear :)
Using the `Pluto.jl` reactive backend, changing a value in some cell will automatically update all other cells - including plots.
We can use Sliders instead of fixing the parameters of the simulation
A slider is defined like this:
```julia
@bind yourVarName PlutoUI.Slider(from:to) # from:step:to is optional, step by def 1
```
## Adding interactivity via sliders
1. Define a slider that controls the number of samples from 1:500
2. Define a second slider that adds a constant offset to all values of the simulation simulation
3. make sure to fix the x/y-limits to get a nice looking plot :-)
:::{.callout-tip collapse="true"}
## Bonus: Advanced slider management
After understanding the slightly awkward syntax, the following gives a nice collection of Sliders, Checkboxes, Widgets etc. with at the same time being drag-and-dropable and in a sidebar. Neat!
If you dont like to use Pluto.jl, you can of course switch back to VSCode. Then you have to create a new environment and add the packages you use before.
:::
## 🥚 vs. 🗓
Visualize the number of eggs against the year
:::callout-tip
To get a first overview, `first(df)` , `describe(df)` and `names(df)` are typically helpful
:::
## Split them up
Next split them up, choose `color` and `col` and choose reasonable columns from the dataset
## Rotate the labels
Use the trick from the handout to modify a plot after it was generated: Rotate the x-label ticks by some 30°
:::callout-tip
instead of rotating each axis manually, you can also replace the `draw` command in your pipeline with an anonymous function. This allows you to specify additional arguments e.g. to the axis, for all "sub"-plots
```julia
... |> x-> draw(x;axis=(;xlims = (-3,2))) # <1>
```
1. Note the `;` before xlims, this enforces that a `NamedTuple` is created