@@ -73,9 +73,9 @@ function factors(table; kind=:form, dim=2)
7373end
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
8080There 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
0 commit comments