Entering edit mode
2.3 years ago
Armin
•
0
Hi everyone
I'm trying to generate a heatmap of fst genetic distance, it used to work perfectly, but now the values are all over when I ask for only the lower part. This is the code I'm using:
jm_fst = genet.dist(juglan_sub, method = "WC84") %>% round(digits = 3)
lab_order = c("GAZ", "UAI", "SEM", "KAR", "AZA", "ZAN", "TOY", "KOR",
"TAB", "DAM", "IPA", "ARD", "GON", "TAF", "ISF",
"GEO", "TAL", "QAZ", "QUC", "EGH", "NAG", "URM", "PAV","DEN", "IRA", "BAM", "NUR")
fst.mat = as.matrix(juglan_fst)
fst.mat1 = fst.mat[lab_order, ]
fst.mat2 = fst.mat1[, lab_order]
fst.df$Site1 = factor(fst.df$Site1, levels = unique(fst.df$Site1))
fst.df$Site2 = factor(fst.df$Site2, levels = unique(fst.df$Site2))
ind = which(upper.tri(fst.mat2), arr.ind = TRUE)
fst.df = data.frame(Site1 = dimnames(fst.mat2)[[2]][ind[,2]],
Site2 = dimnames(fst.mat2)[[1]][ind[,1]],
Fst = fst.mat2[ ind ])
fst.df %>% str
mid = max(fst.df$Fst) / 2
ggplot(data = fst.df, aes(x = Site1, y = Site2, fill = Fst))+
geom_tile(colour = "black")+
geom_text(aes(label = Fst), color="black", size = 3)+
scale_fill_gradient2(low = "blue", mid = "pink", high = "red", midpoint = mid, name = fst.label, limits = c(0, max(fst.df$Fst)), breaks = c(0, 0.05, 0.10, 0.15))+
scale_x_discrete(expand = c(0,0))+
scale_y_discrete(expand = c(0,0), position = "right")+
theme(axis.text = element_text(colour = "black", size = 10, face = "bold"),
axis.title = element_blank(),
panel.grid = element_blank(),
panel.background = element_blank(),
legend.position = "right",
legend.title = element_text(size = 14, face = "bold"),
legend.text = element_text(size = 10)
)