View source: R/con_pv_dist_transit.R
1 | con_pv_dist_transit(alloutputs, cutoff, folder, pvtitle, pvpicdim)
|
alloutputs |
|
cutoff |
|
folder |
|
pvtitle |
|
pvpicdim |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | ##---- 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, cutoff, folder, pvtitle, pvpicdim)
{
library(ggplot2)
dir.create(path = folder, showWarnings = FALSE)
df <- alloutputs$alldist$pvdist
df <- data.frame(df)
df$pvalue <- 10^(-as.numeric(as.character((df[, "rep"]))))
difseq <- unique(alloutputs$alldist$psigdist[, 6])
lowindx <- length(difseq) - 1
scenario0 <- df[df$dif == 0, ]
scenario0$Status <- "stay"
scenario0[scenario0$pvalue > cutoff, "Status"] <- paste("leave",
cutoff, sep = "")
if (length(unique(scenario0$Status)) == 1) {
cl0 <- "#00BFC4"
}
else {
cl0 <- c("#F8766D", "#00BFC4")
}
p <- ggplot(scenario0, aes(x = pvalue, fill = Status)) +
xlim(0, 1) + geom_histogram(color = "black", fill = "#00BFC4",
bins = 21, position = "stack", boundary = 0) + scale_fill_manual(values = cl0)
sc <- ggplot_build(p)$data[1]
p <- p + geom_vline(aes(xintercept = cutoff), color = "#ff00cc",
linetype = "dashed", size = 2, show.legend = F) + geom_text(aes(x = cutoff,
label = paste("p=", cutoff, eps = ""), y = -0.5), colour = "blue",
vjust = 1.2, size = 5) + ylim(c(-0.5, 1.1 * max(sc[[1]]$y)))
if (!is.null(pvtitle)) {
p <- p + ggtitle(paste(pvtitle, "permutation proportion",
round(i/lowindx, 2), sep = " "))
}
p + theme_bw() + theme(plot.title = element_text(hjust = 0.5,
size = 30), legend.title = element_text(size = 20), legend.text = element_text(size = 12)) +
theme(panel.background = element_blank(), axis.text = element_text(size = 24,
face = "bold"), axis.title = element_text(size = 20,
face = "bold"), panel.border = element_rect(colour = "black",
fill = NA, size = 0.5))
ggsave(filename = paste(folder, "/", round(0/lowindx, 2),
"_permute", "_pvalue.eps", sep = ""), width = 7, height = 7)
list0 <- (scenario0$pvalue < cutoff)
len0 <- sum(list0)
for (i in 1:lowindx) {
scenario <- df[df$dif == difseq[i + 1], ]
temp <- scenario[1:len0, ]
scenario$Status <- "stay"
scenario[c(temp$pvalue > cutoff, rep(FALSE, dim(scenario)[1] -
len0)), "Status"] <- paste("leave", cutoff, sep = "")
if (length(unique(scenario$Status)) == 2) {
cl <- c("#F8766D", "#00BFC4")
}
else {
if (unique(scenario$Status) == "stay") {
cl <- "#00BFC4"
}
else {
cl <- "#F8766D"
}
}
p <- ggplot(scenario, aes(x = pvalue, fill = Status)) +
xlim(0, 1) + geom_histogram(color = "black", bins = 21,
position = "stack", boundary = 0) + scale_fill_manual(values = cl)
p <- p + geom_vline(aes(xintercept = cutoff), color = "#ff00cc",
linetype = "dashed", size = 2, show.legend = F) +
geom_text(aes(x = cutoff, label = paste("p=", cutoff,
eps = ""), y = -0.5), colour = "blue", vjust = 1.2,
size = 5) + ylim(c(-0.5, 1.1 * max(sc[[1]]$y)))
if (!is.null(pvtitle)) {
p <- p + ggtitle(paste(pvtitle, "permutation proportion",
round(0/lowindx, 2), sep = " "))
}
p + theme_bw() + theme(plot.title = element_text(hjust = 0.5,
size = 30), legend.title = element_text(size = 20),
legend.text = element_text(size = 12)) + theme(panel.background = element_blank(),
axis.text = element_text(size = 24, face = "bold"),
axis.title = element_text(size = 20, face = "bold"),
panel.border = element_rect(colour = "black", fill = NA,
size = 0.5))
ggsave(filename = paste(folder, "/", round(i/lowindx,
2), "_permute", "_pvalue.eps", sep = ""), width = 7,
height = 7)
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.