Skip to content

Commit 613f95e

Browse files
committed
Refactor package for latest Makie.jl
1 parent 3b19846 commit 613f95e

File tree

8 files changed

+34
-45
lines changed

8 files changed

+34
-45
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Biplots"
22
uuid = "9eb8d32e-48e1-486a-8aed-3d24e9b2252a"
33
authors = ["Júlio Hoffimann <julio.hoffimann@gmail.com> and contributors"]
4-
version = "1.1.2"
4+
version = "1.2.0"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -11,9 +11,9 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1111
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
1212

1313
[compat]
14-
Makie = "0.20, 0.21, 0.22"
14+
Makie = "0.24"
1515
Tables = "1.7"
16-
julia = "1.6"
16+
julia = "1.10"
1717

1818
[extras]
1919
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Build Status](https://github.com/juliohm/Biplots.jl/workflows/CI/badge.svg)](https://github.com/juliohm/Biplots.jl/actions)
44

5-
[Biplot](https://en.wikipedia.org/wiki/Biplot) recipes in 2D and 3D for Makie.jl.
5+
[Biplot](https://en.wikipedia.org/wiki/Biplot) recipes for Makie.jl.
66

77
## Installation
88

@@ -50,10 +50,10 @@ names = [:Black,:White,:Blue,:Red,:Yellow,:Other]
5050
# choose any Tables.jl table
5151
table = (; zip(names, eachcol(data))...)
5252

53-
# 2D relative variation biplot with colored dots
53+
# relative variation biplot with colored dots
5454
fig, ax = biplot(table, kind = :rform, dotcolor = table.Red)
5555
ax.aspect = DataAspect()
5656
```
57-
![biplot2D](docs/biplot2D.png)
57+
![biplot](docs/biplot.png)
5858

5959
Please check the docstring `?biplot` for available attributes.
File renamed without changes.

src/Biplots.jl

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ function factors(table; kind=:form, dim=2)
7373
end
7474

7575
"""
76-
biplot(table; kind=:form, dim=2, [aesthetics...])
76+
biplot(table; kind=:form, [aesthetics...])
7777
78-
Biplot of `table` of given `kind` in `dim`-dimensional space.
78+
Biplot of `table` of given `kind` in 2-dimensional space.
7979
8080
There are four kinds of biplots:
8181
@@ -87,18 +87,17 @@ There are four kinds of biplots:
8787
# Biplot attributes
8888
8989
* `kind` - kind of biplot (`:form`, `:cov`, `:rform` or `:rcov`)
90-
* `dim` - number of dimensions `dim ∈ {2,3}` (default to `2`)
9190
9291
# Aesthetics attributes
9392
9493
* `axescolormap` - colormap of principal axes (default to theme colormap)
9594
* `dotcolormap` - colormap of sample dots (default to theme colormap)
9695
* `fontsize` - font size in axes and dots (default to `12`)
97-
* `axesbody` - size of principal axes' body (depends on `dim`)
98-
* `axeshead` - size of principal axes' head (depends on `dim`)
96+
* `axesbody` - size of principal axes' body (default to `2`)
97+
* `axeshead` - size of principal axes' head (default to `8`)
9998
* `axescolor` - color of principal axes (default to `:black`)
10099
* `axeslabel` - names of principal axes (default to `x1,x2,...`)
101-
* `dotsize` - size of sample dots (depends on `dim`)
100+
* `dotsize` - size of sample dots (default to `4`)
102101
* `dotcolor` - color of sample dots (default to `:black`)
103102
* `dotlabel` - names of sample dots (default to `1:nobs`)
104103
* `showdots` - show names of dots (default to `true`)
@@ -119,16 +118,15 @@ See https://en.wikipedia.org/wiki/Biplot.
119118
Makie.Attributes(;
120119
# biplot attributes
121120
kind = :form,
122-
dim = 2,
123121

124122
# aesthetic attributes
125123
axescolormap = Makie.theme(scene, :colormap),
126124
dotcolormap = Makie.theme(scene, :colormap),
127125
fontsize = 12,
128-
axesbody = nothing,
129-
axeshead = nothing,
126+
axesbody = 2,
127+
axeshead = 8,
130128
axescolor = :black,
131-
dotsize = nothing,
129+
dotsize = 4,
132130
dotcolor = :black,
133131
dotlabel = nothing,
134132
showdots = true,
@@ -140,7 +138,6 @@ function Makie.plot!(plot::Biplot{<:Tuple{Any}})
140138
# biplot attributes
141139
table = plot[:table][]
142140
kind = plot[:kind][]
143-
dim = plot[:dim][]
144141

145142
# aesthetics attributes
146143
axescolormap = plot[:axescolormap][]
@@ -155,28 +152,22 @@ function Makie.plot!(plot::Biplot{<:Tuple{Any}})
155152
showdots = plot[:showdots][]
156153
showlinks = plot[:showlinks][]
157154

155+
# dimension of the biplot
156+
dim = 2
157+
158158
# biplot factors
159159
F, G, σ² = factors(table, kind=kind, dim=dim)
160160

161161
# n samples x p variables
162162
n = size(F, 1)
163163
p = size(G, 1)
164164

165-
# defaults differ on 2 or 3 dimensions
166-
if isnothing(axesbody)
167-
axesbody = dim == 2 ? 2 : 0.01
168-
end
169-
if isnothing(axeshead)
170-
axeshead = dim == 2 ? 14 : 0.03
171-
end
165+
# defaults aesthetics
172166
if axescolor isa AbstractVector{<:Number}
173167
min, max = extrema(axescolor)
174168
axesscale(x) = x / (max-min) - min / (max - min)
175169
axescolor = Makie.cgrad(axescolormap)[axesscale.(axescolor)]
176170
end
177-
if isnothing(dotsize)
178-
dotsize = dim == 2 ? 4 : 10
179-
end
180171
if isnothing(dotlabel)
181172
dotlabel = string.(1:n)
182173
end
@@ -187,22 +178,21 @@ function Makie.plot!(plot::Biplot{<:Tuple{Any}})
187178
end
188179

189180
# plot principal axes
190-
points = fill(Makie.Point(ntuple(i->0., dim)), n)
181+
origin = fill(Makie.Point(ntuple(i->0.0, dim)), p)
191182
direcs = [Makie.Vec{dim}(v) for v in eachrow(G)]
192-
Makie.arrows!(plot, points, direcs,
193-
linewidth = axesbody,
194-
arrowsize = axeshead,
195-
arrowcolor = axescolor,
196-
linecolor = axescolor,
183+
Makie.arrows2d!(plot, origin, direcs,
184+
shaftwidth = axesbody,
185+
tipwidth = axeshead,
186+
color = axescolor
197187
)
198188

199189
# plot axes names
200-
position = Tuple.(direcs)
201-
names = Tables.columnnames(table)
202-
Makie.text!(plot, collect(string.(names)),
203-
position = position,
204-
fontsize = fontsize,
205-
color = axescolor,
190+
cols = Tables.columns(table)
191+
names = [string(n) for n in Tables.columnnames(cols)]
192+
Makie.annotation!(plot, direcs,
193+
text = names,
194+
textcolor = axescolor,
195+
fontsize = fontsize
206196
)
207197

208198
# plot links between axes
@@ -229,13 +219,12 @@ function Makie.plot!(plot::Biplot{<:Tuple{Any}})
229219
color = dotcolor,
230220
)
231221

222+
# plot samples names
232223
if showdots
233-
# plot samples names
234-
position = Tuple.(points)
235-
Makie.text!(plot, dotlabel,
236-
position = position,
237-
fontsize = fontsize,
238-
color = dotcolor,
224+
Makie.annotation!(plot, points,
225+
text = dotlabel,
226+
textcolor = dotcolor,
227+
fontsize = fontsize
239228
)
240229
end
241230

test/data/cov.png

4.9 KB
Loading

test/data/form.png

1.83 KB
Loading

test/data/rcov.png

4.11 KB
Loading

test/data/rform.png

3.31 KB
Loading

0 commit comments

Comments
 (0)