Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
started markdown file
  • Loading branch information
sebastianlieske committed Jan 30, 2019
1 parent 1bd8bba commit 09c2934
Show file tree
Hide file tree
Showing 10 changed files with 524,910 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
@@ -0,0 +1,2 @@
^.*\.Rproj$
^\.Rproj\.user$
2 changes: 2 additions & 0 deletions NAMESPACE
@@ -1,6 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(make.kruskal.frame)
import(data.table)
import(ggplot2)
importFrom(dplyr,group_by_)
importFrom(dplyr,summarize)
importFrom(magrittr,"%>%")
52 changes: 52 additions & 0 deletions R/plot.graph.R
@@ -0,0 +1,52 @@
#' Plot graphs
#' @description Plot different charts.
#' @param data Input data e.g. data frame
#' @param type Type of graph e.g. ("boxplot", "violinplot", "jitterplot", "barplot")
#' @param x Values for x-axis, e.g. values of a column to be passed to aes(x = ...) of \link{ggplot2}
#' @param y Values for y-axis, values of a column to be passed to aes(y = ...) of \link{ggplot2}
#' @param geom_plot_args A list of rguments to \link{ggplot2}
#' @import ggplot2
#' @import data.table
#' @examples
#' brainCalculatedMetadata <- calculate.metadata(metadata, brainRows)
#' @return

plot.graph <- function(data, type = "jitter", x, y, geom_plot_args = list()) {
#check if data is a data table
if (!is.data.table(data)) data <- data.table(data)
if(type == "boxplot") {
ggplot(data, aes(x = data[[x]], y = data[[y]])) +
do.call("geom_boxplot", geom_plot_args) +
xlab(x) +
ylab(y)
}
else if(type == "violinplot") {
ggplot(data, aes(x = data[[x]], y = data[[y]])) +
do.call("geom_violin", geom_plot_args) +
geom_jitter(size = 0.4, width = 0.15) +
stat_summary(fun.data = summary.violin, color = "black") +
xlab(x) +
ylab(y)
}
else if(type == "jitter") {
ggplot(data, aes(x = data[[x]], y = data[[y]])) +
do.call("geom_jitter", geom_plot_args) +
xlab(x) +
ylab(y)
}
else if(type == "barplot") {
ggplot(data, aes(x = data[[x]])) +
do.call("geom_bar", geom_plot_args) +
xlab(x) +
ylab(y)
}
}

#' Calculation of median + range
#' @param x Input from ggplot
summary.violin <- function(x) {
mu <- mean(x)
sigma1 <- mu-sd(x)
sigma2 <- mu+sd(x)
return(c(y=mu, ymin=sigma1, ymax=sigma2))
}

0 comments on commit 09c2934

Please sign in to comment.