-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from iuliadmtru/svyplot
Implement `svyplot` function with documentation and test
- Loading branch information
Showing
5 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
``` | ||
svyplot(design, x, y; weights, kwargs...) | ||
``` | ||
Scatter plot of survey design variables `x` and `y`. | ||
Weights can be specified by a `Symbol` or an `AbstractVector` passed to the | ||
keyword argument `weights`. | ||
For the complete argument list see [Makie.scatter](https://makie.juliaplots.org/stable/examples/plotting_functions/scatter/index.html#scatter). | ||
```@example svyplot | ||
julia> using survey | ||
julia> data(api); | ||
julia> dstrat = svydesign(data = apistrat, id = :1, strata = :stype, weights = :pw, fpc = :fpc); | ||
julia> s = svyplot(dstrat, :api99, :api00; weights = :pw) | ||
``` | ||
![](./assets/scatter.png) | ||
""" | ||
function svyplot(design::svydesign, x::Symbol, y::Symbol; | ||
weights::Union{Symbol, AbstractVector} = ones(size(design.variables, 1)), | ||
kwargs... | ||
) | ||
xs = design.variables[!, x] | ||
ys = design.variables[!, y] | ||
|
||
if isa(weights, Symbol) | ||
weights = design.variables[!, weights] | ||
end | ||
|
||
scatter(xs, ys; markersize = weights, marker = '○', kwargs...) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ end | |
|
||
include("svyglm.jl") | ||
include("svyhist.jl") | ||
include("svyplot.jl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Survey | ||
using Test | ||
|
||
@testset "svyplot.jl" begin | ||
data(api) | ||
dstrat = svydesign(data = apistrat, id = :1, strata = :stype, weights = :pw, fpc = :fpc) | ||
s = svyplot(dstrat, :api99, :api00; weights = :pw) | ||
|
||
@test getindex(s.plot.markersize) == dstrat.variables[!, :pw] | ||
end |