One way to do it is below.
library(dartRverse)
t1 <-
platypus.glCR_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)