stuff
This commit is contained in:
parent
7bed6a1e22
commit
d5da923a74
1 changed files with 102 additions and 23 deletions
|
@ -1,6 +1,6 @@
|
||||||
#source("~/git/LSHTM_analysis/config/alr.R")
|
source("~/git/LSHTM_analysis/config/alr.R")
|
||||||
#source("~/git/LSHTM_analysis/scripts/plotting/get_plotting_dfs.R")
|
source("~/git/LSHTM_analysis/scripts/plotting/get_plotting_dfs.R")
|
||||||
#source("~/git/LSHTM_analysis/scripts/plotting/plotting_colnames.R")
|
source("~/git/LSHTM_analysis/scripts/plotting/plotting_colnames.R")
|
||||||
|
|
||||||
#=======
|
#=======
|
||||||
# output
|
# output
|
||||||
|
@ -8,14 +8,31 @@
|
||||||
#outdir_images = paste0("/home/pub/Work/LSHTM/Thesis_Plots/pairs/")
|
#outdir_images = paste0("/home/pub/Work/LSHTM/Thesis_Plots/pairs/")
|
||||||
#cat("plots will output to:", outdir_images)
|
#cat("plots will output to:", outdir_images)
|
||||||
|
|
||||||
custom_cor <- function(data, mapping, method, ...){
|
custom_cor <- function(
|
||||||
|
data,
|
||||||
|
mapping,
|
||||||
|
method,
|
||||||
|
digits=2,
|
||||||
|
use="complete.obs",
|
||||||
|
stars=TRUE,
|
||||||
|
...
|
||||||
|
){
|
||||||
x <- eval_data_col(data, mapping$x)
|
x <- eval_data_col(data, mapping$x)
|
||||||
y <- eval_data_col(data, mapping$y)
|
y <- eval_data_col(data, mapping$y)
|
||||||
|
|
||||||
corr <- cor(x, y, method=method, use='complete.obs')
|
corr_obj <- stats::cor.test(x, y, method=method, use=use)
|
||||||
|
cor_est <- as.numeric(corr_obj$estimate)
|
||||||
|
cor_txt <- formatC(cor_est, digits = digits, format = "f")
|
||||||
|
|
||||||
|
cor_txt = paste0("ρ: ",as.character(round(cor_txt, 2)))
|
||||||
|
if (isTRUE(stars)) {
|
||||||
|
cor_txt <- str_c(cor_txt, signif_stars(corr_obj$p.value))
|
||||||
|
}
|
||||||
|
corr_obj$p.value
|
||||||
|
cor_txt
|
||||||
|
|
||||||
ggally_text(
|
ggally_text(
|
||||||
label = paste0("ρ: ",as.character(round(corr, 2))),
|
label = cor_txt,
|
||||||
mapping = aes(),
|
mapping = aes(),
|
||||||
xP = 0.5, yP = 0.5,
|
xP = 0.5, yP = 0.5,
|
||||||
color = 'black',
|
color = 'black',
|
||||||
|
@ -24,22 +41,83 @@ custom_cor <- function(data, mapping, method, ...){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
custom_corr2=function (data, mapping, ..., stars = TRUE, method = "pearson",
|
||||||
|
use = "complete.obs", display_grid = FALSE, digits = 3,
|
||||||
|
title_args = list(...), group_args = list(...), justify_labels = "right",
|
||||||
|
align_percent = 0.5, title = "ρ", alignPercent = warning("deprecated. Use `align_percent`"),
|
||||||
|
displayGrid = warning("deprecated. Use `display_grid`"))
|
||||||
|
{
|
||||||
|
if (!missing(alignPercent)) {
|
||||||
|
warning("`alignPercent` is deprecated. Please use `align_percent` if alignment still needs to be adjusted")
|
||||||
|
align_percent <- alignPercent
|
||||||
|
}
|
||||||
|
if (!missing(displayGrid)) {
|
||||||
|
warning("`displayGrid` is deprecated. Please use `display_grid`")
|
||||||
|
display_grid <- displayGrid
|
||||||
|
}
|
||||||
|
na.rm <- if (missing(use)) {
|
||||||
|
NA
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
(use %in% c("complete.obs", "pairwise.complete.obs",
|
||||||
|
"na.or.complete"))
|
||||||
|
}
|
||||||
|
|
||||||
my_gg_pairs=function(plot_df, plot_title
|
|
||||||
, tt_args_size = 2.5
|
|
||||||
, gp_args_size = 2.5){
|
ggally_statistic(data = data,
|
||||||
|
mapping = mapping,
|
||||||
|
na.rm = na.rm,
|
||||||
|
align_percent = align_percent,
|
||||||
|
display_grid = display_grid,
|
||||||
|
title_args = title_args,
|
||||||
|
group_args = group_args,
|
||||||
|
justify_labels = justify_labels,
|
||||||
|
justify_text = "left",
|
||||||
|
sep = if ("colour" %in% names(mapping))
|
||||||
|
": "
|
||||||
|
else ": ", title = title, text_fn = function(x, y) {
|
||||||
|
# if (is_date(x)) {
|
||||||
|
# x <- as.numeric(x)
|
||||||
|
# }
|
||||||
|
# if (is_date(y)) {
|
||||||
|
# y <- as.numeric(y)
|
||||||
|
# }
|
||||||
|
corObj <- stats::cor.test(x, y, method = method,
|
||||||
|
use = use)
|
||||||
|
cor_est <- as.numeric(corObj$estimate)
|
||||||
|
cor_txt <- formatC(cor_est, digits = digits, format = "f")
|
||||||
|
if (isTRUE(stars)) {
|
||||||
|
cor_txt <- str_c(cor_txt, signif_stars(corObj$p.value))
|
||||||
|
}
|
||||||
|
cor_txt
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
my_gg_pairs=function(
|
||||||
|
plot_df,
|
||||||
|
plot_title
|
||||||
|
, tt_args_size = 5
|
||||||
|
, gp_args_size = 5
|
||||||
|
){
|
||||||
ggpairs(plot_df,
|
ggpairs(plot_df,
|
||||||
columns = 1:(ncol(plot_df)-1),
|
columns = 1:(ncol(plot_df)-1),
|
||||||
upper = list(
|
upper = list(
|
||||||
continuous = wrap(custom_cor, method="spearman"
|
continuous = wrap(
|
||||||
# ggally_cor, # ggally_cor()
|
#ustom_cor, method="spearman"
|
||||||
# method = "spearman",
|
custom_corr2, # ggally_cor()
|
||||||
# use = "pairwise.complete.obs",
|
method = "spearman",
|
||||||
# title="XXX ρ",
|
use = "pairwise.complete.obs",
|
||||||
# digits=2,
|
#title="XXX ",
|
||||||
# justify_labels = "centre",
|
digits=2,
|
||||||
# title_args=list(size=tt_args_size, colour="black")#,#2.5
|
justify_labels = "centre",
|
||||||
# #group_args=list(size=gp_args_size)#2.5
|
title_args=list(size=tt_args_size, colour="black")#,#2.5
|
||||||
|
#group_args=list(size=gp_args_size)#2.5
|
||||||
|
, size=10
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
lower = list(
|
lower = list(
|
||||||
|
@ -175,6 +253,7 @@ plot_corr_df_aff = my_gg_pairs(corr_df_aff
|
||||||
#, gp_args_size = 4
|
#, gp_args_size = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
#### Combine plots #####
|
#### Combine plots #####
|
||||||
# #png("/home/tanu/tmp/gg_pairs_all.png", height = 6, width=11.75, unit="in",res=300)
|
# #png("/home/tanu/tmp/gg_pairs_all.png", height = 6, width=11.75, unit="in",res=300)
|
||||||
# png(paste0(outdir_images
|
# png(paste0(outdir_images
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue