Skip to content

Cannot re-level strata of a snpclone object #244

@Neato-Nick

Description

@Neato-Nick

Please place an "x" in all the boxes that apply

  • I have the most recent version of poppr and R
  • I have found a bug
  • I want to request a new feature

Strata do not keep factor leveling. I noticed that snpclone objects immediately reset to their own leveling whenever a factor is releveled. In an MSN, I'd like the populations to appear in a specific order, so I tried to put the levels in the right order like I typically do for ggplot but that did not work

I don't know if this is solvable at least at the snpclone level, and I recognize this may be a few steps away from poppr's problem:

  • Adegenet: strata of genlight objects also cannot be releveled
  • Base plot: Do the factor levels even get used for plotting, or if I solve the re-leveling issue will the populations still be in the original order?

I'd appreciate any advice to go from here, thanks

library(poppr)
#> Loading required package: adegenet
#> Loading required package: ade4
#> Registered S3 method overwritten by 'spdep':
#>   method   from
#>   plot.mst ape
#> 
#>    /// adegenet 2.1.3 is loaded ////////////
#> 
#>    > overview: '?adegenet'
#>    > tutorials/doc/questions: 'adegenetWeb()' 
#>    > bug reports/feature requests: adegenetIssues()
#> Registered S3 method overwritten by 'pegas':
#>   method      from
#>   print.amova ade4
#> This is poppr version 2.9.2. To get started, type package?poppr
#> OMP parallel support: available

dat <- list(toto=c(1,1,0,0), titi=c(NA,1,1,0), tata=c(NA,0,1, NA))
x <- new("genlight", dat)
x <- as.snpclone(x)
strata(x) <- data.frame(ind = c("toto", "titi", "tata"), year = c(2003, 2001, 2002))
# Original levels
levels(strata(x)$year)
#> [1] "2003" "2001" "2002"
# Order I want the factor in for plotting
levels(factor(strata(x)$year, levels = c(2001, 2002, 2003)))
#> [1] "2001" "2002" "2003"
# Assign to that order
strata(x)$year <- factor(strata(x)$year, levels = c(2001, 2002, 2003))
# Assignment did not take
levels(strata(x)$year)
#> [1] "2003" "2001" "2002"

setPop(x) <- ~year
poppr.msn(x, bitwise.dist(x), showplot = TRUE)

#> $graph
#> IGRAPH 6c5624c UNW- 3 2 -- 
#> + attr: name (v/c), size (v/n), shape (v/c), pie (v/x), pie.color
#> | (v/x), color (v/c), label (v/c), weight (e/n), color (e/c), width
#> | (e/n)
#> + edges from 6c5624c (vertex names):
#> [1] toto--titi titi--tata
#> 
#> $populations
#> [1] "2003" "2001" "2002"
#> 
#> $colors
#>      2003      2001      2002 
#> "#4C00FF" "#00FF4D" "#FFFF00"

Created on 2021-07-06 by the reprex package (v2.0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions