How to create a graph like this

Just found a piece of code(see the link below), want to generate similar graph, but it doesn't come up, what is wrong? Thank you!

library(adegenet)
data(dapcIllus)
x <- dapcIllus$a
grp <- find.clusters(x, max.n.clust = 40)
dapc1 <- dapc(x, grp$grp)
scatter(dapc1)

Cna3R

It looks like agegenet will interactively prompt the user for some parameters if none are explicitly given. This is basically a recipe for non-reproducible code. I'm going to add this to my list of junk one should never do.

So I can only guess what options the person creating your example chose. But here's an example with the parameters stated:

``` r

library(adegenet)
#> Loading required package: ade4
#> 
#>    /// adegenet 2.1.1 is loaded ////////////
#> 
#>    > overview: '?adegenet'
#>    > tutorials/doc/questions: 'adegenetWeb()' 
#>    > bug reports/feature requests: adegenetIssues()

data(dapcIllus)
x <- dapcIllus$a
grp <- find.clusters(x, max.n.clust = 40, n.pca=6,n.clust=6)
dapc1 <- dapc(x, grp$grp, n.pca=6,n.clust=5,n.da=5)
scatter(dapc1)

Created on 2018-09-06 by the reprex
package
(v0.2.0).

6 Likes

Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

May I ask another question? What type of data is dapcIllus? looks it is neither data frame nor matrix, the first time I saw such data?

It's a list. If you're in R Studio you can determine that from looking in the environment:

Or from within R:

library(adegenet)
data(dapcIllus)

str(dapcIllus)
#> List of 4
#>  $ a:Formal class 'genind' [package ""] with 11 slots
#>   .. ..@ tab      : int [1:600, 1:140] 1 1 1 2 1 2 1 1 2 1 ...
#>   .. .. ..- attr(*, "dimnames")=List of 2
#>   .. .. .. ..$ : chr [1:600] "1" "2" "3" "4" ...
#>   .. .. .. ..$ : chr [1:140] "loc-1.03" "loc-1.19" "loc-2.01" "loc-2.04" ...
#>   .. ..@ loc.fac  : Factor w/ 30 levels "L01","L02","L03",..: 1 1 2 2 2 2 2 3 3 3 ...
#>   .. ..@ loc.n.all: Named int [1:30] 2 5 4 3 8 3 3 5 7 5 ...
#>   .. .. ..- attr(*, "names")= chr [1:30] "L01" "L02" "L03" "L04" ...
#>   .. ..@ all.names:List of 30
#>   .. .. ..$ L01: Named chr [1:2] "03" "19"
#>   .. .. .. ..- attr(*, "names")= chr [1:2] "1" "2"
#>   .. .. ..$ L02: Named chr [1:5] "01" "04" "40" "41" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L03: Named chr [1:4] "08" "10" "38" "45"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L04: Named chr [1:3] "22" "36" "49"
#>   .. .. .. ..- attr(*, "names")= chr [1:3] "1" "2" "3"
#>   .. .. ..$ L05: Named chr [1:8] "04" "08" "15" "17" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:8] "1" "2" "3" "4" ...
#>   .. .. ..$ L06: Named chr [1:3] "14" "15" "33"
#>   .. .. .. ..- attr(*, "names")= chr [1:3] "1" "2" "3"
#>   .. .. ..$ L07: Named chr [1:3] "06" "37" "40"
#>   .. .. .. ..- attr(*, "names")= chr [1:3] "1" "2" "3"
#>   .. .. ..$ L08: Named chr [1:5] "10" "21" "33" "44" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L09: Named chr [1:7] "01" "13" "24" "25" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L10: Named chr [1:5] "03" "22" "30" "37" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L11: Named chr [1:8] "05" "11" "16" "21" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:8] "1" "2" "3" "4" ...
#>   .. .. ..$ L12: Named chr [1:4] "01" "09" "20" "21"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L13: Named chr [1:3] "34" "44" "47"
#>   .. .. .. ..- attr(*, "names")= chr [1:3] "1" "2" "3"
#>   .. .. ..$ L14: Named chr [1:3] "30" "48" "50"
#>   .. .. .. ..- attr(*, "names")= chr [1:3] "1" "2" "3"
#>   .. .. ..$ L15: Named chr [1:2] "21" "30"
#>   .. .. .. ..- attr(*, "names")= chr [1:2] "1" "2"
#>   .. .. ..$ L16: Named chr [1:6] "10" "12" "14" "25" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L17: Named chr [1:4] "06" "23" "38" "46"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L18: Named chr [1:4] "02" "25" "49" "50"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L19: Named chr [1:6] "01" "13" "37" "43" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L20: Named chr [1:6] "11" "12" "17" "20" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L21: Named chr [1:8] "04" "15" "17" "31" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:8] "1" "2" "3" "4" ...
#>   .. .. ..$ L22: Named chr [1:3] "20" "24" "49"
#>   .. .. .. ..- attr(*, "names")= chr [1:3] "1" "2" "3"
#>   .. .. ..$ L23: Named chr [1:5] "11" "25" "38" "43" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L24: Named chr [1:3] "02" "12" "43"
#>   .. .. .. ..- attr(*, "names")= chr [1:3] "1" "2" "3"
#>   .. .. ..$ L25: Named chr [1:5] "18" "23" "28" "30" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L26: Named chr [1:4] "01" "02" "23" "30"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L27: Named chr [1:5] "03" "06" "22" "24" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L28: Named chr [1:7] "07" "13" "14" "20" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L29: Named chr [1:4] "14" "17" "30" "44"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L30: Named chr [1:5] "26" "34" "42" "49" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. ..@ ploidy   : int [1:600] 2 2 2 2 2 2 2 2 2 2 ...
#>   .. ..@ type     : chr "codom"
#>   .. ..@ other    : NULL
#>   .. ..@ call     : language read.fstat(file = file, missing = missing, quiet = quiet)
#>   .. ..@ pop      : Factor w/ 6 levels "P1","P2","P3",..: 1 1 1 1 1 1 1 1 1 1 ...
#>   .. ..@ strata   : NULL
#>   .. ..@ hierarchy: NULL
#>  $ b:Formal class 'genind' [package ""] with 11 slots
#>   .. ..@ tab      : int [1:600, 1:163] 0 0 0 0 0 0 0 0 0 0 ...
#>   .. .. ..- attr(*, "dimnames")=List of 2
#>   .. .. .. ..$ : chr [1:600] "1" "2" "3" "4" ...
#>   .. .. .. ..$ : chr [1:163] "loc-1.16" "loc-1.19" "loc-1.33" "loc-1.40" ...
#>   .. ..@ loc.fac  : Factor w/ 30 levels "L01","L02","L03",..: 1 1 1 1 2 2 3 3 3 3 ...
#>   .. ..@ loc.n.all: Named int [1:30] 4 2 7 6 5 4 5 6 7 6 ...
#>   .. .. ..- attr(*, "names")= chr [1:30] "L01" "L02" "L03" "L04" ...
#>   .. ..@ all.names:List of 30
#>   .. .. ..$ L01: Named chr [1:4] "16" "19" "33" "40"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L02: Named chr [1:2] "02" "15"
#>   .. .. .. ..- attr(*, "names")= chr [1:2] "1" "2"
#>   .. .. ..$ L03: Named chr [1:7] "06" "07" "08" "15" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L04: Named chr [1:6] "02" "04" "06" "18" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L05: Named chr [1:5] "06" "30" "31" "46" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L06: Named chr [1:4] "01" "09" "39" "41"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L07: Named chr [1:5] "09" "16" "20" "22" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L08: Named chr [1:6] "01" "02" "15" "19" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L09: Named chr [1:7] "01" "09" "13" "23" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L10: Named chr [1:6] "03" "14" "41" "46" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L11: Named chr [1:10] "02" "12" "13" "21" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:10] "01" "02" "03" "04" ...
#>   .. .. ..$ L12: Named chr [1:8] "03" "18" "19" "26" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:8] "1" "2" "3" "4" ...
#>   .. .. ..$ L13: Named chr [1:6] "10" "11" "13" "26" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L14: Named chr [1:4] "06" "09" "14" "30"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L15: Named chr [1:4] "15" "37" "41" "46"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L16: Named chr [1:5] "02" "04" "07" "11" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L17: Named chr [1:4] "16" "19" "38" "50"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L18: Named chr [1:4] "03" "09" "32" "49"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L19: Named chr [1:7] "01" "09" "22" "25" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L20: Named chr [1:5] "04" "17" "20" "22" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L21: Named chr [1:6] "07" "14" "16" "32" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L22: Named chr [1:4] "18" "23" "40" "45"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L23: Named chr [1:4] "23" "28" "34" "47"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L24: Named chr [1:7] "11" "15" "20" "23" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L25: Named chr [1:6] "02" "10" "23" "29" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L26: Named chr [1:5] "07" "13" "14" "36" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L27: Named chr [1:4] "32" "38" "39" "46"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L28: Named chr [1:7] "06" "08" "20" "22" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L29: Named chr [1:6] "09" "10" "19" "22" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L30: Named chr [1:5] "12" "13" "17" "46" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. ..@ ploidy   : int [1:600] 2 2 2 2 2 2 2 2 2 2 ...
#>   .. ..@ type     : chr "codom"
#>   .. ..@ other    : NULL
#>   .. ..@ call     : language read.fstat(file = file, missing = missing, quiet = quiet)
#>   .. ..@ pop      : Factor w/ 6 levels "P1","P2","P3",..: 1 1 1 1 1 1 1 1 1 1 ...
#>   .. ..@ strata   : NULL
#>   .. ..@ hierarchy: NULL
#>  $ c:Formal class 'genind' [package ""] with 11 slots
#>   .. ..@ tab      : int [1:600, 1:160] 0 0 0 0 0 0 0 0 0 0 ...
#>   .. .. ..- attr(*, "dimnames")=List of 2
#>   .. .. .. ..$ : chr [1:600] "1" "2" "3" "4" ...
#>   .. .. .. ..$ : chr [1:160] "loc-1.03" "loc-1.34" "loc-1.45" "loc-2.01" ...
#>   .. ..@ loc.fac  : Factor w/ 30 levels "L01","L02","L03",..: 1 1 1 2 2 2 2 2 2 2 ...
#>   .. ..@ loc.n.all: Named int [1:30] 3 7 8 5 7 6 8 7 4 7 ...
#>   .. .. ..- attr(*, "names")= chr [1:30] "L01" "L02" "L03" "L04" ...
#>   .. ..@ all.names:List of 30
#>   .. .. ..$ L01: Named chr [1:3] "03" "34" "45"
#>   .. .. .. ..- attr(*, "names")= chr [1:3] "1" "2" "3"
#>   .. .. ..$ L02: Named chr [1:7] "01" "07" "10" "25" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L03: Named chr [1:8] "04" "05" "07" "20" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:8] "1" "2" "3" "4" ...
#>   .. .. ..$ L04: Named chr [1:5] "04" "08" "41" "46" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L05: Named chr [1:7] "01" "11" "12" "14" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L06: Named chr [1:6] "16" "25" "28" "29" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L07: Named chr [1:8] "05" "08" "13" "24" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:8] "1" "2" "3" "4" ...
#>   .. .. ..$ L08: Named chr [1:7] "03" "14" "26" "33" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L09: Named chr [1:4] "05" "14" "19" "23"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L10: Named chr [1:7] "04" "15" "20" "22" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L11: Named chr [1:3] "19" "30" "46"
#>   .. .. .. ..- attr(*, "names")= chr [1:3] "1" "2" "3"
#>   .. .. ..$ L12: Named chr [1:7] "01" "04" "11" "18" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L13: Named chr [1:5] "10" "22" "24" "28" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L14: Named chr [1:5] "16" "18" "25" "27" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L15: Named chr [1:4] "15" "22" "26" "33"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L16: Named chr [1:5] "02" "31" "32" "41" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L17: Named chr [1:4] "07" "08" "20" "32"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L18: Named chr [1:5] "08" "15" "19" "28" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L19: Named chr [1:5] "17" "33" "34" "43" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L20: Named chr [1:4] "12" "17" "22" "27"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L21: Named chr [1:3] "10" "14" "41"
#>   .. .. .. ..- attr(*, "names")= chr [1:3] "1" "2" "3"
#>   .. .. ..$ L22: Named chr [1:6] "02" "04" "09" "14" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L23: Named chr [1:6] "20" "21" "26" "29" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L24: Named chr [1:7] "06" "09" "12" "18" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L25: Named chr [1:3] "26" "32" "40"
#>   .. .. .. ..- attr(*, "names")= chr [1:3] "1" "2" "3"
#>   .. .. ..$ L26: Named chr [1:6] "18" "28" "29" "45" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L27: Named chr [1:4] "06" "34" "46" "49"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L28: Named chr [1:5] "17" "19" "29" "36" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L29: Named chr [1:4] "01" "11" "21" "30"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L30: Named chr [1:7] "07" "12" "18" "23" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. ..@ ploidy   : int [1:600] 2 2 2 2 2 2 2 2 2 2 ...
#>   .. ..@ type     : chr "codom"
#>   .. ..@ other    : NULL
#>   .. ..@ call     : language read.fstat(file = file, missing = missing, quiet = quiet)
#>   .. ..@ pop      : Factor w/ 12 levels "P01","P02","P03",..: 1 1 1 1 1 1 1 1 1 1 ...
#>   .. ..@ strata   : NULL
#>   .. ..@ hierarchy: NULL
#>  $ d:Formal class 'genind' [package ""] with 11 slots
#>   .. ..@ tab      : int [1:600, 1:185] 0 0 0 0 0 0 0 0 0 0 ...
#>   .. .. ..- attr(*, "dimnames")=List of 2
#>   .. .. .. ..$ : chr [1:600] "1" "2" "3" "4" ...
#>   .. .. .. ..$ : chr [1:185] "loc-1.11" "loc-1.15" "loc-1.36" "loc-2.18" ...
#>   .. ..@ loc.fac  : Factor w/ 30 levels "L01","L02","L03",..: 1 1 1 2 2 2 2 2 3 3 ...
#>   .. ..@ loc.n.all: Named int [1:30] 3 5 5 10 5 7 7 5 7 6 ...
#>   .. .. ..- attr(*, "names")= chr [1:30] "L01" "L02" "L03" "L04" ...
#>   .. ..@ all.names:List of 30
#>   .. .. ..$ L01: Named chr [1:3] "11" "15" "36"
#>   .. .. .. ..- attr(*, "names")= chr [1:3] "1" "2" "3"
#>   .. .. ..$ L02: Named chr [1:5] "18" "20" "31" "44" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L03: Named chr [1:5] "05" "19" "27" "33" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L04: Named chr [1:10] "08" "16" "17" "18" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:10] "01" "02" "03" "04" ...
#>   .. .. ..$ L05: Named chr [1:5] "12" "14" "35" "39" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L06: Named chr [1:7] "05" "13" "18" "20" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L07: Named chr [1:7] "02" "09" "27" "28" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L08: Named chr [1:5] "28" "32" "34" "40" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L09: Named chr [1:7] "02" "05" "06" "15" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L10: Named chr [1:6] "11" "23" "35" "41" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L11: Named chr [1:6] "01" "15" "34" "35" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L12: Named chr [1:9] "03" "04" "08" "11" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:9] "1" "2" "3" "4" ...
#>   .. .. ..$ L13: Named chr [1:7] "03" "10" "12" "20" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L14: Named chr [1:7] "02" "03" "13" "14" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L15: Named chr [1:5] "16" "34" "40" "45" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L16: Named chr [1:5] "03" "04" "06" "19" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L17: Named chr [1:5] "06" "15" "23" "25" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L18: Named chr [1:6] "04" "06" "19" "32" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L19: Named chr [1:9] "07" "19" "20" "21" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:9] "1" "2" "3" "4" ...
#>   .. .. ..$ L20: Named chr [1:7] "03" "05" "09" "10" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L21: Named chr [1:6] "01" "05" "15" "21" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L22: Named chr [1:9] "07" "08" "11" "14" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:9] "1" "2" "3" "4" ...
#>   .. .. ..$ L23: Named chr [1:7] "12" "14" "17" "19" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:7] "1" "2" "3" "4" ...
#>   .. .. ..$ L24: Named chr [1:5] "05" "07" "08" "23" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L25: Named chr [1:5] "08" "19" "21" "22" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. .. ..$ L26: Named chr [1:2] "14" "25"
#>   .. .. .. ..- attr(*, "names")= chr [1:2] "1" "2"
#>   .. .. ..$ L27: Named chr [1:4] "01" "08" "22" "30"
#>   .. .. .. ..- attr(*, "names")= chr [1:4] "1" "2" "3" "4"
#>   .. .. ..$ L28: Named chr [1:10] "09" "16" "17" "18" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:10] "01" "02" "03" "04" ...
#>   .. .. ..$ L29: Named chr [1:6] "07" "16" "21" "28" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:6] "1" "2" "3" "4" ...
#>   .. .. ..$ L30: Named chr [1:5] "14" "17" "27" "32" ...
#>   .. .. .. ..- attr(*, "names")= chr [1:5] "1" "2" "3" "4" ...
#>   .. ..@ ploidy   : int [1:600] 2 2 2 2 2 2 2 2 2 2 ...
#>   .. ..@ type     : chr "codom"
#>   .. ..@ other    : NULL
#>   .. ..@ call     : language read.fstat(file = file, missing = missing, quiet = quiet)
#>   .. ..@ pop      : Factor w/ 24 levels "P01","P02","P03",..: 1 1 1 1 1 1 1 1 1 1 ...
#>   .. ..@ strata   : NULL
#>   .. ..@ hierarchy: NULL

Created on 2018-09-07 by the reprex
package
(v0.2.0).

2 Likes

Got it. Thank you so much!

The question is, how would you handle the situation if you had written the code?

The rationale for the behavior of interactively seeking parameters based on user input is avoiding the user randomly choosing parameters without considering the structure of the data. To be fair, this design choice was carried over from the ade4 package, but it's become clear that users get confused as to how to set these parameters to avoid the interactive use.

One potential solution I've suggested was to amend the user's command with the chosen parameters and show it as a message for them to copy+paste into their code. The downside of this is that users may not read the messages that are thrown at them.

Another solution I can think of is to break out the decision steps of this function into user-facing interactive functions that return the parameters. This way, if the user doesn't specify a parameter, the function stops and the error message instructs them to use choose_npca() or choose_nda() to obtain their parameters.

@zkamvar, I take it you're the package author?

Yeah I see the design challenge being faced here. I had on my "reproducible workflow" hat and clearly you wrote that with an "interactive analysis" mindset. Thus the impedance mismatch.

So, yeah, there are trade offs.

The big trade off I see is that by requiring interactive input you force input from outside the script which prevents reproducibility.

Keep in mind that I've never used this package in anger and never heard of it until I saw this question. So I could be completely out of touch with the zeitgeist of the package.

No, but I have contributed quite a bit to it!

Though, as you demonstrated above, the interactivity is only an ephemeral part of the analysis and can be circumvented by supplying parameter values. The issue with this analysis is that it is easy to over-fit the data and obtain answers that are not generalizable, so the users either need to see the plots showing the cumulative variance so that they can make a rough guess, or they need to do a cross-validation procedure.

It was designed so that they could go back and cement the parameters in there for reproducibility once they had finished with EDA.

That makes sense. Thanks for explaining. I know package maintenance is a lot of work!