Plotting Loc CR by population?

7 views
Skip to first unread message

Gabriella Scatà

unread,
Jun 25, 2024, 7:29:04 PM (7 days ago) Jun 25
to dartR
Hi everyone,
I was wondering whether there is any function in dartR/dartR.base that allows to plot Loc CR by population.
I keep getting weird results in the diagnostics plots of OUTFLANK, indicating that the Locus sample size may not be the same across all populations...so I would like to check this.

I thought of plotting the locus metrics against individual metrics population info,  but these are in two different slots in the dartR object, and I am not too sure how to do this at this stage.
If there was already a function it would be great, otherwise I will keep playing with it.

Thanks
Gabriella

Jose Luis Mijangos

unread,
Jun 25, 2024, 8:24:55 PM (7 days ago) Jun 25
to dartR
Hi Gabriella,

One way to do it is below.

Cheers,
Luis 

library(dartRverse)
t1 <- platypus.gl

CR_bypop <- function(x) {
  CR_byind <- 1 - rowSums(is.na(as.matrix(x))) / nLoc(x)
  # Combine call rate and population information
  callrate_df <- data.frame(
    individual = indNames(x),
    callrate = CR_byind,
    population = pop(x)
  )
 
  # Plot call rate by population
  p1 <- ggplot(callrate_df,
               aes(
                 x = population,
                 y = callrate,
                 fill = population,
                 color = population
               )) +
    geom_boxplot(alpha = 1 / 2,
                 show.legend = FALSE) +
    theme_bw() +
    labs(title = "Call Rate by Population", y = "Call Rate")
 
  print(p1)
 
  return(callrate_df)
}

res <- CR_bypop(t1)

Gabriella Scatà

unread,
Jul 2, 2024, 9:19:58 PM (4 hours ago) Jul 2
to dartR
Hi Luis,
thank you for that sorry for the slow reply.
I'll test it and let you know!
Best
Gabriella

Reply all
Reply to author
Forward
0 new messages