p_hat <- colMeans(y) / 2
sd_hat <- sqrt(pmax(1e-6, 2 * p_hat * (1 - p_hat)))
Z <- scale(y, center = 2 * p_hat, scale = sd_hat)
pc <- prcomp(Z, center = FALSE, scale. = FALSE)
pc_df <- data.frame(PC1 = pc$x[, 1], PC2 = pc$x[, 2], pi1 = pi_true[, 1])
ggplot(pc_df, aes(PC1, PC2, color = pi1)) +
geom_point(alpha = 0.7, size = 1.6) +
scale_color_viridis_c(end = .8) +
labs(color = expression(pi[1]), x = "PC1", y = "PC2") +
geom_vline(xintercept = 2.75, linetype = "dashed", color = "gray40", linewidth = 0.6) +
geom_vline(xintercept = -2.75, linetype = "dashed", color = "gray40", linewidth = 0.6) +
annotate("text", x = 4.5, y = 6, label = "Pop 1", color = "gray20", size = 6) +
annotate("text", x = -4.5, y = 6, label = "Pop 2", color = "gray20", size = 6) +
annotate("text", x = 0, y = 6, label = "Admixed", color = "gray20", size = 6) +
theme_bw(base_size = 14) +
theme(panel.grid = element_blank())