Skip to content

Commit

Permalink
Option for no sorting in caterpillarplot! (#12)
Browse files Browse the repository at this point in the history
* Zenodo badge

* orderby nothing

* patch bump

* remove extra newline

* use the correct index

* drop support for julia-1.5

* swap to PNG due to SVG bug

* sorting note

* Tighten the code a bit.

Co-authored-by: Douglas Bates <[email protected]>
  • Loading branch information
palday and dmbates authored May 17, 2021
1 parent a948ac4 commit 135ab62
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
version: [1.5, 1]
version: [1]
arch: [x64]
os: [ubuntu-18.04] # macos-10.15, windows-2019
steps:
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MixedModelsMakie"
uuid = "b12ae82c-6730-437f-aff9-d2c38332a376"
authors = ["Phillip Alday <[email protected]> and contributors"]
version = "0.1.0"
authors = ["Phillip Alday <[email protected]>, Douglas Bates <[email protected]> and contributors"]
version = "0.1.1"

[deps]
AbstractPlotting = "537997a7-5e4e-5d89-9595-2241ea00577e"
Expand All @@ -13,7 +13,7 @@ MixedModels = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316"
AbstractPlotting = "0.18"
DataFrames = "1"
MixedModels = "3.6, 4"
julia = "1.5"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
[![Stable Docs][docs-stable-img]][docs-stable-url]
[![Dev Docs][docs-dev-img]][docs-dev-url]
[![Codecov](https://codecov.io/gh/palday/MixedModelsMakie.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/palday/MixedModelsMakie.jl)
[![DOI](https://zenodo.org/badge/337082315.svg)](https://zenodo.org/badge/latestdoi/337082315)


[docs-dev-img]: https://img.shields.io/badge/docs-dev-blue.svg
[docs-dev-url]: https://palday.github.io/MixedModelsMakie.jl/dev
Expand Down
6 changes: 5 additions & 1 deletion docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ caterpillar!

```@example Caterpillar
using CairoMakie
CairoMakie.activate!(type = "svg")
CairoMakie.activate!(type = "png")
using MixedModels
using MixedModelsMakie
sleepstudy = MixedModels.dataset(:sleepstudy)
Expand All @@ -43,6 +43,10 @@ caterpillar!(Figure(; resolution=(800,600)), subjre)
caterpillar!(Figure(; resolution=(800,600)), subjre; orderby=2)
```

```@example Caterpillar
caterpillar!(Figure(; resolution=(800,600)), subjre; orderby=nothing)
```

## Shrinkage Plots

```@docs
Expand Down
2 changes: 1 addition & 1 deletion src/MixedModelsMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ module MixedModelsMakie
include("caterpillar.jl")
include("xyplot.jl")

end
end # module
11 changes: 9 additions & 2 deletions src/caterpillar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ Add Axes of a caterpillar plot from `r` to `f`.
The order of the levels on the vertical axes is increasing `orderby` column
of `r.ranef`, usually the `(Intercept)` random effects.
Setting `orderby=nothing` will disable sorting, i.e. return the levels in the
order they are stored in.
!!! note
Even when not sorting the levels, they might have already been sorted during
model matrix construction. If you want impose a particular ordering on the
levels, then you must sort the relevant fields in the `RanefInfo` object before
calling `caterpillar!`.
"""
function caterpillar!(f::Figure, r::RanefInfo; orderby=1)
rr = r.ranef
vv = view(rr, :, orderby)
ord = sortperm(vv)
y = axes(rr, 1)
ord = isnothing(orderby) ? y : sortperm(view(rr, :, orderby))
cn = r.cnames
axs = [Axis(f[1, j]) for j in axes(rr, 2)]
linkyaxes!(axs...)
Expand Down

2 comments on commit 135ab62

@palday
Copy link
Owner Author

@palday palday commented on 135ab62 May 17, 2021

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/36910

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.1 -m "<description of version>" 135ab628e7c5baf5ffc252cebfd7c27fb8a6e312
git push origin v0.1.1

Please sign in to comment.