Skip to content

Commit

Permalink
Add plots to docs (#12)
Browse files Browse the repository at this point in the history
* add plots to docs

* color

* fix scope of fig

* use dot

* show plot only once

* ci on tags

* wip

* bump version
  • Loading branch information
greimel authored Feb 15, 2021
1 parent 41edb61 commit 7480f03
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
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

2 comments on commit 7480f03

@greimel
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/30086

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.2 -m "<description of version>" 7480f0376395812adb7112cc164a47a67c5b7bee
git push origin v0.1.2

Please sign in to comment.