#' Plot network simulation data
#'
library(tidyverse)
plot_data <- function(pgs_mean, nones_mean, ess_mean, pgs_data, nones_data, ess_data, binwidth = 1, xlim = 1, title) {
mean_df <- bind_rows(
data.frame(data = pgs_mean, group = "Proto-gene"), data.frame(data = nones_mean, group = "Non-essential"),
data.frame(data = ess_mean, group = "Essential")
)
mean_df$group <- factor(mean_df$group, levels = c("Proto-gene", "Non-essential", "Essential"))
p12 <- sum(abs(mean_df$data[mean_df$group == "Proto-gene"]) - abs(mean_df$data[mean_df$group == "Non-essential"]) <= 0) / length(mean_df$data[mean_df$group == "Proto-gene"])
p13 <- sum(abs(mean_df$data[mean_df$group == "Proto-gene"]) - abs(mean_df$data[mean_df$group == "Essential"]) <= 0) / length(mean_df$data[mean_df$group == "Proto-gene"])
p23 <- sum(abs(mean_df$data[mean_df$group == "Non-essential"]) - abs(mean_df$data[mean_df$group == "Essential"]) <= 0) / length(mean_df$data[mean_df$group == "Proto-gene"])
ggbox <- ggplot(
mean_df,
aes(x = group, y = data, fill = group)
) + geom_boxplot() + scale_x_discrete(labels = element_blank()) +
ylab("Mean") + xlab("") + theme(legend.position = "none", axis.title.y = element_text(size = 25)) + scale_fill_manual(values = c("#00BFC4", "#FF3300", "orange")) #+ # ggplot(subset(sm.list2,group=='proto-gene'),aes(x=group,color=group))+geom_boxplot(aes(y=betweenness))
# geom_signif(
# annotations = c('ns', '****','****' ),
# y_position = c(max(mean_df$data) +1, max(mean_df$data) + 4, max(mean_df$data) + 2.5), xmin = c(1, 1, 2), xmax = c(2, 3, 3)
# )
data_comb_df <- bind_rows(data.frame(data = pgs_data, group = "Proto-gene"), data.frame(data = nones_data, group = "Non-essential"), data.frame(data = ess_data, group = "Essential"))
data_comb_df$group <- factor(data_comb_df$group, levels = c("Proto-gene", "Non-essential", "Essential"))
ggline <- ggplot(data_comb_df, aes(x = (data), color = group, fill = group)) +
geom_freqpoly(aes(y = c(
..count..[..group.. == 1] / sum(..count..[..group.. == 1]),
..count..[..group.. == 2] / sum(..count..[..group.. == 2]),
..count..[..group.. == 3] / sum(..count..[..group.. == 3])
)),
position = "identity", binwidth = binwidth
) + xlim(xlim, NA) + labs(color = "") + scale_color_manual(values = c("#00BFC4", "#FF3300", "orange")) + theme(legend.position = "none", axis.title.y = element_text(size = 30), axis.title.x = element_text(size = 30)) + # scale_fill_discrete(name='')+
ylab("Percentage") + xlab(title) + scale_y_continuous(labels = scales::percent) # sm.l# pgs.data <- as.tbl(data.frame(matrix(ncol=7,nrow=86)))
combplot <- ggdraw() + # draw_label(title,hjust=0,y=0.99)+
draw_plot(ggline + theme(legend.justification = "bottom"), 0, 0, 1, 1) +
draw_plot(ggbox + # scale_color_viridis(discrete = TRUE) +
theme(legend.justification = "top"), 0.45, 0.4, 0.58, 0.59)
list(combplot, p12, p13, p23)
}
#' Plot network simulation data using cumulative distr
require(scales) # to access break formatting functions
plot_data_ecdf <- function(pgs_data, nones_data, ess_data, binwidth = 1, xlim = 1, title = "", logscale = T, legend = T) {
data_comb_df <- bind_rows(data.frame(data = pgs_data, group = "Proto-gene"), data.frame(data = nones_data, group = "Non-essential"), data.frame(data = ess_data, group = "Essential"))
data_comb_df$group <- factor(data_comb_df$group, levels = c("Proto-gene", "Non-essential", "Essential"))
ggline <- data_comb_df %>% ggplot(aes(x = data, color = group)) + geom_line(aes(y = 1 - ..y..), stat = "ecdf") +
labs(color = "") + scale_color_manual(values = c("#1CBDC2", "#EF3D23", "#FAA51A")) +
theme_me_line + # scale_fill_discrete(name='')+
ylab("Cumulative Distribution") + xlab(title) # sm.l# pgs.data <- as.tbl(data.frame(matrix(ncol=7,nrow=86)))
if (logscale) {
ggline <- ggline + scale_x_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x))) +
scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x))) + annotation_logticks()#scale_x_log10()+scale_y_log10()#+ scale_y_continuous(labels = scales::percent)+annotation_logticks()
} else {
ggline <- ggline #+ scale_y_continuous(labels = scales::percent)
}
if (legend) {
ggline <- ggline
} else {
ggline <- ggline + theme(legend.position = "none")
}
ggline
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.