Code Monkey home page Code Monkey logo

Comments (1)

zkamvar avatar zkamvar commented on June 26, 2024 1

Hi @Neato-Nick,

Sorry for the late reply. This is more of an adegenet, issue, but I will still tackle it here.

There are two solutions for this issue depending on the problem you are trying to solve:

  1. To adjust how the strata are plotted in the legend for the MSN, rearrange them in the MSN object
  2. if you want to re-level the strata for the data set itself so you don't have to constantly rearrange the levels, then the best method is to use the x@strata$year to set it directly (yes, I cringe at this because I spent years telling people to not use the slot directly, but this is literally the only way [see below])

Note: be careful because levels(x) <- sort(levels(x)) does not rearrange the levels like you want it to do, it re-assigns the levels, so your data will all be mis-labeled:

x <- factor(c("b", "a", "c"), levels = c("b", "a", "c"))
x
#> [1] b a c
#> Levels: b a c
levels(x) <- sort(levels(x))
x
#> [1] a b c
#> Levels: a b c

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

What you want is to recreate the factor all together:

x <- factor(c("b", "a", "c"), levels = c("b", "a", "c"))
x
#> [1] b a c
#> Levels: b a c
x <- factor(x, sort(levels(x)))
x
#> [1] b a c
#> Levels: a b c

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

Why does adegenet force the strata to be in the order of observation?

Honestly, I'm not sure. If you look at the code that controls strata()<-, you can see that it will force-reorder the data: https://github.com/thibautjombart/adegenet/blob/e03d87382117a5fcaa914928f8ec37dc72d267cd/R/strataMethods.R#L29-L44

You'll have to ask 2015 Zhian for why he thought that was a good idea, but I think the idea was that people would have prepared their data in a specific order before reading it into R, so we wanted to respect that ordering.

from poppr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.