View source: R/plot_con_permute_sigcurve.R
1 | plot_con_permute_sigcurve(alloutputs, samsize, lgndcol = 2, psigtitle, savepsigfile, psigpicdim)
|
alloutputs |
|
samsize |
|
lgndcol |
|
psigtitle |
|
savepsigfile |
|
psigpicdim |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (alloutputs, samsize, lgndcol = 2, psigtitle, savepsigfile,
psigpicdim)
{
require(ggplot2)
results <- alloutputs$alldist
selname0 <- alloutputs$selname
df <- as.data.frame(results$psigdist)
df$highlight <- ifelse(df$dif == 0, "real data", "permutation")
df$highlight <- factor(df$highlight, levels = c("real data",
"permutation"))
df$prop <- df$median/samsize
mycolours <- c(permutation = "black", `real data` = "red")
N0 <- max(df$dif)
if (sum(is.na(df))) {
stop("Missing values exist in psigdist")
}
else {
df$dif <- df$dif/N0
auc <- DescTools::AUC(df$dif, df$prop, method = "trapezoid",
na.rm = FALSE)
aoi <- mean(df$prop[c(1, length(df$prop))])
slope <- diff(df$prop)/diff(df$dif)
ggplot(df, aes(x = dif, y = prop)) + geom_point(size = 5,
aes(colour = highlight)) + scale_color_manual("Scenarios",
values = mycolours) + geom_pointrange(aes(ymin = q1/samsize,
ymax = q2/samsize, colour = highlight), size = 0.5) +
geom_line(size = 1) + geom_ribbon(aes(ymin = 0, ymax = prop),
alpha = 0.2, fill = "purple") + geom_ribbon(aes(ymin = prop,
ymax = prop[1]), alpha = 0.2, fill = "green") + geom_ribbon(aes(ymin = prop[1],
ymax = 1), alpha = 0.2, fill = "gold") + xlab("Proportion of exchanges") +
ylab("Proportion of significant features") + ggtitle(psigtitle) +
ylim(c(0, 1)) + annotate("text", x = 0.5, y = 0.9,
label = paste("aoi=", round(aoi, 3)), size = 6, colour = "green") +
annotate("text", x = 0.5, y = 0.8, label = paste("auc=",
round(auc, 3)), size = 6, colour = "purple") +
annotate("text", x = 0.5, y = 0.7, label = paste("slope=",
round(slope[1], 3)), size = 6, colour = "red") +
theme_bw() + theme(plot.title = element_text(size = 30,
face = "bold"), legend.title = element_text(size = 20),
legend.text = element_text(size = 16)) + theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(), panel.border = element_blank(),
panel.background = element_blank(), axis.line.x = element_line(color = "black",
size = 1.5), axis.line.y = element_line(color = "black",
size = 1.5), axis.text = element_text(size = 16,
face = "bold"), axis.title = element_text(size = 20,
face = "bold"))
ggsave(filename = savepsigfile, width = psigpicdim[1],
height = psigpicdim[2], device = cairo_ps)
return(list(auc = auc, aoi = aoi, slope = slope, df = df))
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.