Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plots to docs #12

Merged
merged 8 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: CI
on:
on:
push:
tags:
- v*
branches:
- main
pull_request:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DINA"
uuid = "2e9d5fb1-712f-4dff-9379-c18f12b3746d"
authors = ["Fabian Greimel <fabgrei@gmail.com> and contributors"]
version = "0.1.1"
version = "0.1.2"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand Down
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
67 changes: 65 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ first(df80, 5)
using DINA
import CSV

var = [:fiinc, :fninc, :ownermort, :ownerhome, :rentalmort, :rentalhome]
byvar = :fiinc # compute deciles of `:fiinc`
inc = :peinc
wgt = :dweght

dbt_var = [:ownermort, :rentalmort, :nonmort, :hwdeb]
var = [[:fiinc, :fninc, :ptinc, inc, :poinc, :ownerhome, :rentalhome]; dbt_var]
byvar = inc # compute deciles of `:peinc`

df = dina_quantile_panel(var, byvar, 10)

Expand All @@ -44,6 +48,65 @@ first(df, 5)

[download](./dina-aggregated.csv)

## Some plots

```@example panel
using DataFrames, CairoMakie
using CairoMakie: AbstractPlotting.wong_colors
using LinearAlgebra: dot

agg_df = let
df1 = select(df,
:group_id,
:age, :year, wgt, var...
)

df2 = combine(
groupby(df1, :year),
([v, wgt] => ((x,w) -> dot(x,w)/sum(w)) => v for v in var)...
)

transform!(df2, ([d, inc] => ByRow(/) => string(d) * "2inc" for d in dbt_var)...)
end

let d = agg_df
fig = Figure()

# Define Layout, Labels, Titles
Label(fig[1,1], "Growth of Household-Debt-To-Income in the USA", tellwidth = false)
axs = [Axis(fig[2,1][1,i]) for i in 1:2]

box_attr = (color = :gray90, )
label_attr = (padding = (3,3,3,3), )

Box(fig[2,1][1,1, Top()]; box_attr...)
Label(fig[2,1][1,1, Top()], "relative to 1980"; label_attr...)

Box(fig[2,1][1,2, Top()]; box_attr...)
Label(fig[2,1][1,2, Top()], "relative to total debt in 1980"; label_attr...)

# Plot
i80 = findfirst(d.year .== 1980)

for (i,dbt) in enumerate(dbt_var)
var = string(dbt) * "2inc"
for (j, fractionof) in enumerate([var, :hwdeb2inc])
lines!(axs[j], d.year, d[!,var]/d[i80,fractionof], label = string(dbt), color = wong_colors[i])
end
end

# Legend
leg_attr = (orientation = :horizontal, tellheight = true, tellwidth = false)
leg = Legend(fig[3,1], axs[1]; leg_attr...)

save("fig_dbt.svg", fig) # hide
fig
nothing # hide
end
```

![fig_dbt](fig_dbt.svg)


```@index
```
Expand Down