Commit 2d26f831 authored by Simon CHEVOLLEAU's avatar Simon CHEVOLLEAU 💻
Browse files

Violin plot is correctly set up

parent 9549e1d9
......@@ -53,38 +53,46 @@ violinPlot <- function(x,
#' Violin plot with a group variable
#'
#' @description Create a violin plot with a possible group variable
#' @param x is a factor variable
#' @param y is value
require(ggplot2)
require(scales)
ifelse(is.null(group), dt <- data.frame(x,y), dt <- data.frame(x,y,group))
dt$x[is.na(dt$x)] <- "Na"
dodge <- position_dodge(width=dodge)
min_value <- min(y) - (max(y) - min(y))
max_value <- max(y) + (max(y) - min(y))
plot_list <- list()
if(is.null(group)){
plot(ggplot(dt, aes(x=as.factor(x), y=y)) +
geom_violin(trim=FALSE) +
stat_summary(fun.data="mean_sdl", fun.args = list(mult = 1), geom="crossbar", width=width, fill="white") +
labs(title=title, x=title.x, y=title.y) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
strip.background =element_rect(fill="white")))
}else{
min_value <- min(y)
max_value <- max(y)
p <- ggplot(dt, aes(x=as.factor(x), y=y)) +labs(title=title, x=title.x, y=title.y, fill=title.group) +
p <- ggplot(dt, aes(x=as.factor(x), y=y)) +
labs(title=title, x=title.x, y=title.y) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
strip.background =element_rect(fill="white")) + ylim(min_value, max_value)
plot(p + geom_violin(aes(fill=as.factor(group)), trim=FALSE, position=dodge) +
geom_boxplot(aes(group=interaction(group,x), fill=as.factor(group)), width=width, outlier.colour=NA, position=dodge))
plot(p + geom_boxplot(aes(fill=as.factor(group)), trim=FALSE, position=dodge) +
facet_wrap( ~ as.factor(x), scales="free") +
scale_y_continuous(trans=logY))
plot(p + geom_violin(aes(fill=as.factor(group)), trim=FALSE, position=dodge) +
facet_wrap( ~ as.factor(x), scales="free") +
scale_y_continuous(trans=logY))
plot_list[["violin_boxplot"]] <- p + geom_violin(trim=FALSE) + geom_boxplot(width=width, outlier.colour=NA, position=dodge) + facet_wrap( ~ as.factor(x), scales="free")
plot_list[["boxplot"]] <- p + geom_boxplot(width=width, outlier.colour=NA, position=dodge) + facet_wrap( ~ as.factor(x), scales="free") + ylim(min(y), max(y))
plot_list[["violin"]] <- p + geom_violin(trim=FALSE) + facet_wrap( ~ as.factor(x), scales="free") + facet_wrap( ~ as.factor(x), scales="free")
}else{
p <- ggplot(dt, aes(x=as.factor(x), y=y)) +labs(title=title, x=title.x, y=title.y, fill=title.group) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
strip.background = element_rect(fill="white")) +
ylim(min_value, max_value)
plot_list[["violin_boxplot"]] <- p + geom_violin(aes(fill=as.factor(group)), trim=FALSE, position=dodge) +
geom_boxplot(aes(group=interaction(group,x), fill=as.factor(group)), width=width, outlier.colour=NA, position=dodge)
plot_list[["boxplot"]] <- p + geom_boxplot(aes(fill=as.factor(group)), width=width, trim=FALSE, position=dodge) +
facet_wrap( ~ as.factor(x), scales="free") +
scale_y_continuous(trans=logY) + ylim(min(y), max(y))
plot_list[["violin"]] <- p + geom_violin(aes(fill=as.factor(group)), trim=FALSE, position=dodge) +
facet_wrap( ~ as.factor(x), scales="free") +
scale_y_continuous(trans=logY)
}
return(plot_list)
}
splitDf <- function(df, annot, n_samples, n_genes, common_row = NULL){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment