Last active
January 21, 2021 23:47
-
-
Save hakyim/72bf6e34a22bbeadb49d95e6b355e088 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##install.packages("ggtern") | |
## library(ggtern) | |
## library(ggplot2) | |
plot_coloc_tern <- function(df) { | |
## function expects a data frame df with column names as follows | |
## coloc_p0 coloc_p1 coloc_p2 coloc_p3 coloc_p4 | |
## 3.776851e-75 1.173353e-08 3.218853e-67 0.9999999326 5.563409e-08 | |
## 2.020855e-107 5.216090e-01 1.633054e-107 0.4214557130 5.693525e-02 | |
## 3.858278e-33 2.548623e-02 2.139795e-33 0.0131732844 9.613405e-01 | |
d <-df %>% filter(is.finite(coloc_p0), is.finite(coloc_p1), is.finite(coloc_p2), is.finite(coloc_p3), is.finite(coloc_p4)) | |
p <- ggtern(d, aes(coloc_p3,coloc_p4, coloc_p0+coloc_p1+coloc_p2)) + | |
stat_density_tern(alpha=0.4, mapping=aes(fill=..level..), geom="polygon", base = "identity") + | |
geom_point(shape = 1, size = 0.5) + | |
scale_fill_gradient(low = "#FFFFFF", high = "#000040") + | |
theme_bw() + | |
scale_T_continuous(breaks = seq(0,1,0.2), labels = c(0,0.2,0.4,0.6,0.8,1)) + | |
scale_L_continuous(breaks = seq(0,1,0.2), labels = c(0,0.2,0.4,0.6,0.8,1)) + | |
scale_R_continuous(breaks = seq(0,1,0.2), labels = c(0,0.2,0.4,0.6,0.8,1)) + | |
theme_showarrows() + | |
xlab("") + | |
ylab("") + | |
zlab("") + | |
Larrowlab("P3") + | |
Tarrowlab("P4") + | |
Rarrowlab("P0+P1+P2") + | |
theme( plot.title = element_text(hjust = 0.5) ) | |
#guides(fill = guide_colorbar()) + | |
#ggtitle(title) | |
return(p) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment