########################################################################################
# name: Cumulative Density Function (cdf)
# author: Marc Bickle, Antje Janosch, Rico
# category: basic/cdf
# preview:
This plot is useful for plotting the cumulative density function of up to 9 populations and verify whether and how they differ
######
$$$TEMPLATE_DESC$$$
# Parameter selection
# a) Define column with categorical values
Group = ;
# b) Define which parameter you would like to visualize
params = c()
########################################################################################
# name: Barplot
# author: Antje Niederlein
# category: basic/barplots
# preview: simplebarplot.png
Flexible template to create a barplot or barplot grid with optional errorbars
Parameter:
Bar height - One or multiple numerical variables. Each value will result in one bar
Error bar checkbox - Draw errorbars?
Error bar - Error bar values corresponding to the height values (same number of columns have to be selected)
To use a flow variable check box and type in variable names using the format: FLOWVAR(variable name)
x-axis - Label to put at the x-axis for each bar (mulitple columns can be selected to combine information)
2D-grid grouping parameter - Allows to split the dataset into multiple plots by this condition (mulitple columns can be selected to combine information)
bar colour - Colour bars by condition (mulitple columns can be selected to combine information)
Enter an additional title
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
# Define your numerical parameters represented by bar height
barHeight = c()
plot.Errorbars =
# Define your numerical parameters for error bars
barError = c()
xFactor = c()
facetBy = c()
colourBy = c()
xAngle = as.numeric(c())
free.scales =
1) {
xFactorCol <- paste(xFactor, collapse = " + ")
kIn[,xFactorCol] <- apply(kIn[,xFactor], 1, paste, collapse = " + ")
}
if(length(facetBy) > 1) {
facetCol <- paste(facetBy, collapse = " + ")
kIn[,facetCol] <- apply(kIn[,facetBy], 1, paste, collapse = " + ")
}
if(length(colourBy) > 1) {
colourCol <- paste(colourBy, collapse = " + ")
kIn[,colourCol] <- apply(kIn[,colourBy], 1, paste, collapse = " + ")
}
# extract necessary data and reshape it
meanData <- kIn[,c(barHeight,xFactorCol, facetCol, colourCol)]
meanDataLong <- melt(meanData, measure.vars = barHeight, variable_name = "- PARAMETERS -")
names(meanDataLong)[which(names(meanDataLong) == "value")] <- "height"
# add errorbar data
if(plot.Errorbars) {
sdData <- kIn[,c(barError,xFactorCol, facetCol, colourCol)]
sdDataLong <- melt(sdData, measure.vars = barError)
meanDataLong$error <- sdDataLong$value
meanDataLong$low <- with(meanDataLong, height - error)
meanDataLong$high <- with(meanDataLong, height + error)
}
if(xFactorFlag) xFactorCol <- "- PARAMETERS -"
if(facetFlag) facetCol <- "- PARAMETERS -"
if(colourFlag) colourCol <- "- PARAMETERS -"
#convert to discrete format
if(!is.null(facetBy)) {
facetTitle <- facetCol
meanDataLong$template.facet.column <- factor(meanDataLong[,facetCol])
facetCol <- "template.facet.column"
}
if(!is.null(colourBy)) meanDataLong[,colourCol] <- factor(meanDataLong[,colourCol])
meanDataLong[,xFactorCol] <- factor(meanDataLong[,xFactorCol])
meanDataLong[,"ggplot_groupid"] <- 1 : nrow(meanDataLong)
# plot data
# -------------------------------------------------------------
p <- ggplot(meanDataLong, aes(x = get(xFactorCol), y = height, group = ggplot_groupid))
my.dodge <- position_dodge(width=0.9)
if(!is.null(colourBy)) {
p <- p + geom_bar(aes(fill = get(colourCol)), stat = "identity", position = my.dodge, colour = "black")
} else {
p <- p + geom_bar(stat = "identity", position = my.dodge, colour = "black", fill = "grey")
}
if(plot.Errorbars) p <- p + geom_errorbar(aes(ymin = low, ymax = high), position = my.dodge, width = 0.35)
p <- p + scale_x_discrete(name = xFactorCol)
if(!is.null(colourCol)) p <- p + scale_fill_discrete(name = colourCol)
if(!is.null(facetBy)) {
p <- p + facet_wrap(~ template.facet.column, scales=free.scales)
fTitle <- paste("Grid factor: ",facetTitle,sep = "")
if(!is.null(plotTitle)) plotTitle <- paste(plotTitle,fTitle,sep = " / ") else plotTitle <- fTitle
p <- p + ggtitle(plotTitle)
} else {
if(!is.null(plotTitle)) p <- p + ggtitle(plotTitle)
}
p <- p + theme_grey(base_size=14) + theme(axis.text.x = element_text(angle = 90, hjust = 1))
print(p)
# -------------------------------------------------------------
]]>
########################################################################################
# name: Barplot with plot options
# author: Antje Niederlein, modified Martin Stoeter
# category: basic/barplots
# preview: simplebarplot.png
Flexible template to create a barplot or barplot grid with optional errorbars
HINT: use GroupBy node to aggregated the data to e.g mean and sd columns
Parameter:
Bar height - One or multiple numerical variables. Each value will result in one bar
Error bar checkbox - Draw errorbars? Choose to plot just positive or negative error bars
Error bar - Error bar values corresponding to the height values (same number of columns have to be selected)
To use a flow variable check box and type in variable names using the format: FLOWVAR(variable name)
x-axis - Label to put at the x-axis for each bar (mulitple columns can be selected to combine information)
2D-grid grouping parameter - Allows to split the dataset into multiple plots by this condition (mulitple columns can be selected to combine information)
bar colour - Colour bars by condition (mulitple columns can be selected to combine information)
Layout Options:
- select background/theme and set general font size in plot (default = 14)
- select different color models for the plot (see: http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/#rcolorbrewer-palette-chart )
- optional the rows and columns can be defined for the 2D grid
- give plot title and title factor (default = 1.2)
- x-axis test: angle, text size factor for x-/y-axis (default = 0.8)
- y-axis title (or use parameter name: for 2D grid => 'height'), axis title factor (default = 1.0)
- adjust y-axis scale (check fixed and enter min + max; free for 2D grid), option for log10 scale and log10 numbers on y-axis
- give legend title, adjust position (fixed position outside diagram or free(range:0-1): [0.1,0.9] = top-left) and legend title/text size factor(default = 0.8)
######
$$$TEMPLATE_DESC$$$
#1.0 Parameter selection
# Define your numerical parameters represented by bar height
barHeight = c()
# Define your numerical parameters for error bars
plot.Errorbars =
plot.Errorbars.Plus =
plot.Errorbars.Negative =
barError = c()
#define use of flow variables
#define x-axis, grid and color group
xFactor = c()
facetBy = c()
colourBy = c()
#diagram options
plotTheme =
plotTextSize = as.numeric(c())
twoDgridRow = c()
twoDgridColumn = c()
plotTitleSize = as.numeric(c())
xAngle = as.numeric(c())
axisTextSizeFactor = as.numeric(c())
useParameternameAsAxisLabel =
axisTitleSizeFactor = as.numeric(c())
useManualYaxisScale =
yAxisScale = as.numeric(c())
free.scales =
yAxisScaleLog10 =
yAxisTextLog10 =
legendPosition =
useLegendCoordinate =
legendCoordinate = as.numeric(c())
legendTitle =
legendTextSizeFactor = as.numeric(c())
rotateLegend =
40)) plotTextSize[1] <- 14
if (is.na(plotTitleSize[1]) | (plotTitleSize[1] < 0) | (plotTitleSize[1] > 5)) plotTitleSize[1] <- 1.2
if (is.na(yAxisLabel)) yAxisLabel <- NULL
if (is.na(xAngle)) xAngle <- 0
if (is.na(axisTextSizeFactor[1]) | (axisTextSizeFactor[1] < 0) | (axisTextSizeFactor[1] > 5)) axisTextSizeFactor[1] <- 0.8
if (is.na(axisTextSizeFactor[2]) | (axisTextSizeFactor[2] < 0) | (axisTextSizeFactor[2] > 5)) axisTextSizeFactor[2] <- 0.8
if (is.na(axisTitleSizeFactor[1]) | (axisTitleSizeFactor[1] < 0) | (axisTitleSizeFactor[1] > 5)) axisTitleSizeFactor[1] <- 1
if (is.na(axisTitleSizeFactor[2]) | (axisTitleSizeFactor[2] < 0) | (axisTitleSizeFactor[2] > 5)) axisTitleSizeFactor[2] <- 1
if (is.na(yAxisScale[1]) | is.na(yAxisScale[2])) yAxisScale <- NULL
if (useParameternameAsAxisLabel) yAxisLabel <- barHeight
if (is.na(legendCoordinate[1]) | is.na(legendCoordinate[2]) | (legendCoordinate[1] < 0) | (legendCoordinate[1] > 1) | (legendCoordinate[2] < 0) | (legendCoordinate[2] > 1)) useLegendCoordinate <- FALSE
if (is.na(legendTextSizeFactor[1]) | (legendTextSizeFactor[1] < 0) | (legendTextSizeFactor[1] > 5)) legendTextSizeFactor[1] <- 0.8
if (is.na(legendTextSizeFactor[2]) | (legendTextSizeFactor[2] < 0) | (legendTextSizeFactor[2] > 5)) legendTextSizeFactor[2] <- 0.8
if (xAngle == 0 ) xAxisAjust <- c(0.5,1.0) #xAxisAjust = c(hjust,vjust)
if (xAngle == 45) xAxisAjust <- c(1.0,1.0)
if (xAngle == 90) xAxisAjust <- c(1.0,0.5)
#2.3 calculate
# create rowID column if needed
if("-ROW ID-" %in% xFactorCol) kIn[,"-ROW ID-"] <- rownames(kIn)
# combine columns if necessary
if(length(xFactor) > 1) {
xFactorCol <- paste(xFactor, collapse = " + ")
kIn[,xFactorCol] <- apply(kIn[,xFactor], 1, paste, collapse = " + ")
}
if(length(facetBy) > 1) {
facetCol <- paste(facetBy, collapse = " + ")
kIn[,facetCol] <- apply(kIn[,facetBy], 1, paste, collapse = " + ")
}
if(length(colourBy) > 1) {
colourCol <- paste(colourBy, collapse = " + ")
kIn[,colourCol] <- apply(kIn[,colourBy], 1, paste, collapse = " + ")
}
# extract necessary data and reshape it
meanData <- kIn[,c(barHeight,xFactorCol, facetCol, colourCol)]
meanDataLong <- melt(meanData, measure.vars = barHeight, variable_name = "- PARAMETERS -")
names(meanDataLong)[which(names(meanDataLong) == "value")] <- "height"
#check if values/data is there, to prevent R error message
if(length(which(!is.na(meanDataLong$height))) == 0){
meanDataLong$height[1] <- 0
plotErrorMessage <- TRUE
} else {
plotErrorMessage <-FALSE
}
# add errorbar data
if(plot.Errorbars) {
sdData <- kIn[,c(barError,xFactorCol, facetCol, colourCol)]
sdDataLong <- melt(sdData, measure.vars = barError)
meanDataLong$error <- sdDataLong$value
if(plot.Errorbars.Negative) {
meanDataLong$low <- with(meanDataLong, height - error)
} else {
meanDataLong$low <- with(meanDataLong, height)
}
if(plot.Errorbars.Plus) {
meanDataLong$high <- with(meanDataLong, height + error)
} else {
meanDataLong$high <- with(meanDataLong, height)
}
if(yAxisScaleLog10) {
meanDataLong[which(meanDataLong$low < 0),"low"] <- 0.000000001
}
}
if(xFactorFlag) xFactorCol <- "- PARAMETERS -"
if(facetFlag) facetCol <- "- PARAMETERS -"
if(colourFlag) colourCol <- "- PARAMETERS -"
if(is.na(legendTitle)) legendTitle <- colourCol #default if no title is given
#convert to discrete format
if(!is.null(facetBy)) {
facetTitle <- facetCol
meanDataLong$template.facet.column <- factor(meanDataLong[,facetCol])
facetCol <- "template.facet.column"
}
if(!is.null(colourBy)) meanDataLong[,colourCol] <- factor(meanDataLong[,colourCol])
meanDataLong[,xFactorCol] <- factor(meanDataLong[,xFactorCol])
meanDataLong[,"ggplot_groupid"] <- 1 : nrow(meanDataLong)
#2.4.1 plot
p <- ggplot(meanDataLong, aes(x = get(xFactorCol), y = height, group = ggplot_groupid))
my.dodge <- position_dodge(width=0.9)
if(!is.null(colourBy)) {
p <- p + geom_bar(aes(fill = get(colourCol)), stat = "identity", position = my.dodge, colour = "black")
} else {
p <- p + geom_bar(stat = "identity", position = my.dodge, colour = "black", fill = "grey")
}
if(plot.Errorbars) p <- p + geom_errorbar(aes(ymin = low, ymax = high), position = my.dodge, width = 0.35)
if(!is.null(facetBy)) {
p <- p + facet_wrap(~ template.facet.column, nrow = twoDgridRow, ncol = twoDgridColumn, scales=free.scales)
fTitle <- paste("Grid factor: ",facetTitle,sep = "")
if(!is.null(plotTitle)) plotTitle <- paste(plotTitle,fTitle,sep = " / ") else plotTitle <- fTitle
p <- p + ggtitle(plotTitle)
} else {
if(!is.null(plotTitle)) p <- p + ggtitle(plotTitle)
}
#2.4.1 layout plot
#general
if(plotTheme == "grey") p <- p + theme_grey(base_size=plotTextSize[1])
if(plotTheme == "black-white") p <- p + theme_bw(base_size=plotTextSize[1])
if(plotTheme == "linedraw") p <- p + theme_linedraw(base_size=plotTextSize[1])
if(plotTheme == "light") p <- p + theme_light(base_size=plotTextSize[1])
if(plotTheme == "classic") p <- p + theme_classic(base_size=plotTextSize[1])
#2.4.2 set general layout of plot
#title options
p <- p + theme(plot.title = element_text(size = plotTextSize[1] * plotTitleSize[1]))
#axis label options
p <- p + scale_x_discrete(name = xFactorCol)
p <- p + theme(axis.title.x = element_text(size = plotTextSize[1] * axisTitleSizeFactor[1]), axis.title.y = element_text(size = plotTextSize[1] * axisTitleSizeFactor[2]))
p <- p + theme(axis.text.x = element_text(angle = xAngle, hjust = xAxisAjust[1], vjust = xAxisAjust[2], size = plotTextSize[1] * axisTextSizeFactor[1]), axis.text.y = element_text(size = plotTextSize[1] * axisTextSizeFactor[2]))
# fixing the y-axis labeling, make parameter name or custom y-axis label instead of "height", only if no multi-parameteric plot and only if no y-Axis label was added in the GUI
if(((!is.null(facetBy) && "-USE COLUMN SELECTION-" %in% facetBy )|| length(barHeight) > 1) && is.null(yAxisLabel)) yAxisLabel <- "height"
#if(useManualYaxisScale) p <- p + scale_y_continuous(limits = yAxisScale, name = yAxisLabel) #use e.g. limits = c(0,100)
if(useManualYaxisScale) p <- p + coord_cartesian(ylim = yAxisScale) # this does not crop the data like "limits" parameter
if(yAxisScaleLog10) {
p <- p + scale_y_log10(name = yAxisLabel) # do y-axis in log 10 scale
if(yAxisTextLog10) p <- p + scale_y_log10(name = yAxisLabel, breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x)))
} else {
p <- p + scale_y_continuous(name = yAxisLabel) # do normal y-axis
if(yAxisTextLog10) p <- p + scale_y_continuous(name = yAxisLabel, breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x)))
}
# color model checks: is it available? is it defined for the grouping column?
if(useKNIMEColors && !exists("kIn.color.model")) {
stop("No KNIME color model provided. Script was stopped!")
useKNIMEColors <- FALSE
}
if(useKNIMEColors && names(kIn.color.model[1]) != colourCol) {
stop(paste("KNIME color model is different (", names(kIn.color.model[1]), ") from selected color grouping column (", colourCol, ") in template. Script was stopped!"))
useKNIMEColors <- FALSE
}
if(useKNIMEColors) {
kIn.color.model <- kIn.color.model[order(kIn.color.model[,colourCol]),]
kIn.color.model$color <- as.character(kIn.color.model$color)
colourCol <- names(kIn.color.model)[1]
factorColors <- kIn.color.model[,2]
names(factorColors) <- kIn.color.model[,1]
}
# color settings
if(useKNIMEColors) {
p <- p + scale_color_manual(name = colourCol, values = factorColors)
p <- p + scale_fill_manual(name = colourCol, values = factorColors)
} else {
if(colorPalette == "ggplot default") {
p <- p + scale_color_discrete(name = colourCol)
p <- p + scale_fill_discrete(name = colourCol)
} else {
p <- p + scale_color_brewer(name = colourCol, palette = colorPalette)
p <- p + scale_fill_brewer(name = colourCol, palette = colorPalette)
}
}
#legend: legend title, text style and rotation
p <- p + guides(color = guide_legend(title = legendTitle), fill = guide_legend(title = legendTitle)) + theme(legend.title = element_text(size = plotTextSize[1] * legendTextSizeFactor[1], face = "bold"), legend.text = element_text(size = plotTextSize[1] * legendTextSizeFactor[2]))
if(rotateLegend) p <- p + guides(fill = guide_legend(title = legendTitle, direction = "horizontal", title.position = "top", label.position = "bottom", label.hjust = 0.5, label.vjust = 0.5, label.theme = element_text(angle = 90)))
if (useLegendCoordinate) {
p <- p + theme(legend.position = legendCoordinate, legend.background = element_rect(fill = "transparent",colour = NA))
} else {
p <- p + theme(legend.position = legendPosition)
}
if(plotErrorMessage) p <- p + ggtitle("ERROR: NO DATA!!!")
print(p)
]]>
########################################################################################
# name: Boxplot (with configuration and flow variable option)
# author: Holger Brandl, Martin Stoeter
# category: basic/boxplots
# preview: simpleboxplot.png
A simple box plot with Options:
- set the y-axis limits (default: none (=automatic); min AND max values are neccessary, if you want to set limits)
- set the magnification factor to be used for axis annotation (default: 1) or set automatically according to number of x-axis factors
- set color of histogram or line (default: lightblue; see colors here http://research.stowers-institute.org/efg/R/Color/Chart/)
- set outer margins in lines of text (vector of form (bottom, left, top, right) corresponding to command "oma" in R)
- to use a flow variable check box and type in variable name using the format: FLOWVAR(variable name)
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
numAttributeName = ;
rawFactor = kIn$;
useVerticalLabels = ;
useParameternameAsAxisLabel =
# 2. r-code
80)) axisAnnotationScale <- sqrt(80)/sqrt(length(levels(factor)))
#4.1 layout plot
par(oma=margins)
#4.2 plot data
if(length(kIn[which(!is.na(numAttribute)),1]) > 0) {#check if data is there
boxplot(numAttribute ~ factor, main = plotTitle, col = color, ylim = yScale, ylab = yAxisLabel, cex.main = mainTitleScale, cex.lab = axisLabelScale, cex.axis = axisAnnotationScale, las = ifelse(useVerticalLabels, 2, 1));
} else {
plot(0,0, main = plotTitle, col = color, ylab = yAxisLabel, las = ifelse(useVerticalLabels, 2, 1))
text(0,0,"no data", col = "black")
}
]]>
########################################################################################
# name: Multi-parameteric parallel boxplot grid
# author: Holger Brandl
# category: _deprecated/basic/boxplots
# preview: multipar-boxplotgrid.png
A grid of parallel boxplots, one for each selected assay parameter. The number of actual parallel boxplots is defined by a categorical variable (like a well-treatment)
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
# a) Define your categorical variable of interest
# make sure that the sorting of the data is being preserved
rawFactor = kIn$;
catVar = factor(rawFactor, levels=unique(rawFactor));
# b) Define your assay parameters of interest
params = which(names(kIn) %in% c());
# 2. r-code
########################################################################################
# name: Notched Boxplot
# author: Holger Brandl
# category: basic/boxplots
# preview: notched-boxplot.png
A boxplot with notches that indicate significant differences of the median between groups in case of equal sample sizes. Refer to the R-documentation or further details.
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
numAttribute = kIn$;
# make sure that the sorting of the data is being preserved
rawFactor = kIn$;
factor = factor(rawFactor, levels=unique(rawFactor));
useVerticalLabels = ;
# 2. r-code
########################################################################################
# name: Parallel Boxplot grid (with flow variable option)
# author: Holger Brandl, modified Martin Stoeter
# category: basic/boxplots
# preview: lattice-boxplotgrid.png
A grid of parallel boxplots.
Inputs
1) The parameter that is plotted
2) A categorial variable which defines the number of parallel boxplots (X-axis factor)
3) A categorial variable which defines the grouping into the different grids
- to use a flow variable check box and type in variable name using the format: FLOWVAR(variable name)
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
numAttributeName =
rawFactor = kIn$
gridFactor = kIn$
########################################################################################
# name: Factorized density grid, KNIME colors
# author: Holger Brandl, modified by Martin Stoeter
# category: basic/histograms
# preview: factorized_density_plot_grid.png
Creates a grid of density plots for selected columns and plots densities for each factor (group).
1) Select numerical variables. Each variable will result in a subplot. Multiple parameters are plotted as grid of subplots.
- To use a flow variable check box and type in variable name using the format: FLOWVAR(variable name) (doesn't work like this for grid of subplots)
2) Select a column that contains the factors/groups of densities to plot.
Options for visualization:
a) how to plot the colors (fill densities or lines).
b) color palette the is used (KNIME colors: if colors were assigned to categories in KMIME and attached to the data table (Color Manager -> Extract Colors -> Join), R will use the R, G, B, A columns to generate the colors for the categories)
c) Select if background should be white.
d) optional title and whether parameter name should be plotted in title
######
$$$TEMPLATE_DESC$$$
#1.0 Parameter selection
# a) Define your numerical attribute of interest
params = c()
# b) Define the grouping factor
factorName = c()
# c) Options for visualization
# d) Define the colour of fill or line
# c) Define the colour of fill or line
colorPalette =
# e) Define the colour of fill or line
# e) set title
1, 2, 1)
numGridCols = ceiling(length(params) / numGridRows)
grid.newpage()
pushViewport(viewport(layout=grid.layout(numGridRows, numGridCols)))
vplayout<-function(x,y) viewport(layout.pos.row = x, layout.pos.col=y)
#2.4.2 plot data
# iterate over all parameters and create plots for all of them
lapply(params, FUN = function (param) {
if (plotLineColour) {
#plot colored lines
m <- ggplot(plotData, aes_string(x = names(plotData)[param], colour = names(plotData)[factorIndex])) + geom_density()
switch(which(colorPalette == c('standard','clarity','KNIME colors','Set1','Set2','Set3','Set4')), {
}, { #standard
if(length(factors) < 9) m <- m + scale_colour_brewer("clarity")}, { #clarity
m <- m + scale_colour_manual(name = origNames[factorIndex], breaks = factors, labels = factors, values = factorColors)}, { #Knime colors
if(length(factors) < 9) m <- m + scale_colour_brewer(name = origNames[factorIndex], palette = "Set1")}, { #Set1
if(length(factors) < 9) m <- m + scale_colour_brewer(name = origNames[factorIndex], palette = "Set2")}, { #Set2
if(length(factors) < 9) m <- m + scale_colour_brewer(name = origNames[factorIndex], palette = "Set3")}, { #Set3
if(length(factors) < 9) m <- m + scale_colour_brewer(name = origNames[factorIndex], palette = "Set4")} #Set4
)
} else {
#plot colored densities
m <- ggplot(plotData, aes_string(x= names(plotData)[param], fill= names(plotData)[factorIndex])) + geom_density(alpha= 0.4)
switch(which(colorPalette == c('standard','clarity','KNIME colors','Set1','Set2','Set3','Set4')), {
}, { #standard
if(length(factors) < 9) m <- m + scale_fill_brewer("clarity")}, { #clarity
m <- m + scale_fill_manual(name = origNames[factorIndex], breaks = factors, labels = factors, values = factorColors)}, { #Knime colors
if(length(factors) < 9) m <- m + scale_fill_brewer(name = origNames[factorIndex], palette = "Set1")}, { #Set1
if(length(factors) < 9) m <- m + scale_fill_brewer(name = origNames[factorIndex], palette = "Set2")}, { #Set2
if(length(factors) < 9) m <- m + scale_fill_brewer(name = origNames[factorIndex], palette = "Set3")}, { #Set3
if(length(factors) < 9) m <- m + scale_fill_brewer(name = origNames[factorIndex], palette = "Set4")} #Set4
)
}
#set the title to the unmodified attribute-name
if (useJoinParameterToTitle) title <- paste(title, origNames[param])
m <- m + xlab(origNames[param]) + labs(fill = origNames[factorIndex]) + ggtitle(title)
plotNum <- which(params == param)
curRow <- ceiling(plotNum/numGridCols)
curCol <- ceiling(plotNum - numGridCols * (curRow-1))
#set background on/off
if (setBkgWhite) m <- m + theme_bw()
print(m, vp=vplayout(curRow, curCol))
})
]]>
########################################################################################
# name: Histogram
# author: Holger Brandl, Martin Stoeter
# category: basic/histograms
# preview: simple_histogram.png
Displays a histogram (distribution) of a numerical attribute.
Allows modification of bins, axis, color, and optional probability density
Options:
- set number of bins: (default: 15)
- set the x and y-axis limits (default: none (=automatic); min AND max values are neccessary, if you want to set limits)
- y-axis is probability density (default: false (=frequency)
- plot density line (default: false)
- set color of histogram or line (default: black; see colors here http://research.stowers-institute.org/efg/R/Color/Chart/)
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
numAttributeName = ;
# 2. r-code
########################################################################################
# name: Histogram grid
# author: Holger Brandl
# category: basic/histograms
# preview: histogram-grid.png
Creates a grid containing a number densityplots, each for a different feature dimension. Within each plot the densities are factorized according to a chosen grouping factor.
1) A selection of numerical variables. Each variable will result in a subplot.
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
# a) Define your numerical attribute of interest
params = which(names(kIn) %in% c());
# c) Define the number of bins
numBins = as.numeric();
1, 2, 1);
numGridCols = ceiling(length(params) / numGridRows);
grid.newpage()
pushViewport(viewport(layout=grid.layout(numGridRows, numGridCols)));
vplayout<-function(x,y) viewport(layout.pos.row = x, layout.pos.col=y);
# iterate over all parameters and create plots for all of them
lapply(params, FUN = function (param) {
varName = names(kIn)[param];
varVect = eval(parse(text = paste("kIn$\"", varName, "\"", sep = '')));
dataRange = range(varVect, na.rm=TRUE);
rangeWidth = dataRange[2] - dataRange[1];
m <- ggplot(kIn, aes_string(x= names(kIn)[param])) + geom_histogram(binwidth= rangeWidth/numBins) + geom_density();
#set the title to the unmodified attribute-name
m <- m + xlab(origNames[param]);
plotNum<- which(params== param);
curRow <- ceiling(plotNum/numGridCols);
curCol <- ceiling(plotNum - numGridCols*(curRow-1));
print(m, vp=vplayout(curRow, curCol));
});
]]>
########################################################################################
# name: Stacked Histogram
# author: Holger Brandl, modified by Antje Niederlein
# category: basic/histograms
# preview: stacked-histogram.png
Displays a stacked histogram (distribution) of a numerical attribute.
Allows modification of number of bins.
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
# a) Define the attribute of interest
numAttributeName = ;
numAttributeIndex = which(names(kIn) == numAttributeName);
# 2) Define the label-column (factor)
labelVariable = ;
labelVariableIndex = which(names(kIn) == labelVariable);
# c) the title of the plot
# d) binwidth
# 2. r-code
########################################################################################
# name: Violin Plot
# author: Martin Stoeter
# category: basic/histograms
# preview: ViolinPlot.png
Creates a Violin plot: for a selected columns and densities for each factor (group).
1) Select numerical variable / parameter
- To use a flow variable check box and type in variable name using the format: FLOWVAR(variable name)
2) Select a column that contains the factors/groups of densities to plot.
Options for visualization:
a) adjust y-axis: default = min-max +/- 5%; optional use of quantiles = (lower quantile * lower scale factor) until (upper quantile * upper scale factor)
extended range factor: e.g. 0.05 extends y-axis by +/- 5%
b) optional title and whether parameter name should be plotted in title
######
$$$TEMPLATE_DESC$$$
#1.0 Parameter selection
# a) Define your numerical attribute of interest
params = c()
# b) Define the grouping factor
factorName = c()
# c) Options for visualization
# e) set title
= 1)) yAxisScaleFactors[1] <- 0
if (is.na(yAxisScaleFactors[2]) | (yAxisScaleFactors[2] <= 0) | (yAxisScaleFactors[2] > 1)) yAxisScaleFactors[2] <- 1
if (is.na(yAxisScaleFactors[3])) yAxisScaleFactors[3] <- 1
if (is.na(yAxisScaleFactors[4])) yAxisScaleFactors[4] <- 1
if (is.na(yAxisScaleFactors[5]) | (useDefaultyAxisScale)) yAxisScaleFactors[5] <- 0.05
if (is.na(title)) title <- NULL
#2.3 calculate
#reshape table and column names to make it work with ggplot(aes(...))
paramIndex <- which(names(kIn) %in% params)
origNames <- names(kIn)
#new ggplot compatible column names
names(kIn)[paramIndex] <- "paramRinternalColumnName"
names(kIn)[factorIndex] <- "treatmentRinternalColumnName"
#set y-axis scale
if (useDefaultyAxisScale) {
yAxisScale <- extendrange(kIn[, paramIndex], f = yAxisScaleFactors[5])
} else {
yAxisScale <- c(quantile(kIn[, paramIndex], na.rm = TRUE, names = FALSE, yAxisScaleFactors[1]), quantile(kIn[, paramIndex], na.rm = TRUE, names = FALSE, yAxisScaleFactors[2])) * c(yAxisScaleFactors[3], yAxisScaleFactors[4])
#check if data is there/yAxisScales are numbers (otherwise plot fails) then do subplot without data (no points are plotted)
if ((is.na(yAxisScale)[1] == TRUE) || (is.na(yAxisScale)[2] == TRUE)
|| (is.infinite(yAxisScale)[1] == TRUE) || (is.infinite(yAxisScale)[2] == TRUE)) {
yAxisScale <- extendrange(kIn[, paramIndex], f = yAxisScaleFactors[5])
} else {
yAxisScale <- extendrange(r = yAxisScale, f = yAxisScaleFactors[5])
}
}
#2.4.1 layout plot
#2.4.2 plot data
m <- ggplot(kIn, aes(x = paramRinternalColumnName)) + stat_density(aes(ymax = ..density.., ymin = -..density..), fill = "grey50", colour = "grey20", geom = "ribbon", position = "identity")
m <- m + scale_x_continuous(limits = yAxisScale)
m <- m + theme(axis.text.x = element_text(angle=90, hjust=1.2, size=8))
m <- m + facet_grid(. ~ treatmentRinternalColumnName) + coord_flip() + theme(panel.grid.minor=element_blank())
if (useJoinParameterToTitle) title <- paste(title, origNames[paramIndex])
m <- m + xlab(origNames[paramIndex]) + labs(fill = origNames[factorIndex]) + ggtitle(title)
print(m)
]]>
########################################################################################
# name: Association Plot
# author: Holger Brandl
# category: basic/others
######
% insert a list of numerical attributes
assocplot(cbind($$ATTRIBUTES$), space=0.5, col=c("black", "red"))
########################################################################################
# name: Cleveland Dot Plot
# author: Holger Brandl
# category: basic/others
######
dotchart($$ATTRIBUTE$, pch='*', "xlab="my label")
########################################################################################
# name: ROC curves
# author: Martin Stoeter
# category: basic/others
# preview: ROC.png
Plots ROC curves (receiver operating characteristic) for several case groups (TP=true positives) against one controls group (TN=true negatives) for each parameter. This results in a curve with "sensitivity" = TPR(true positive rate) on y-axis and "1-specificity" = FPR (false positive rate) on the x-axis.
1) Select numerical variables for ROC curves (parameter).
2) Template expects a column named "treatment" as category column. Enter the name of the negative control class as plain text. Select several classes as positive controls (cases) that will be plotted against the single negative control class (controls).
Options for visualization:
a) plot method can be "automatic" (=done with R package "pROC") or "manual" (=plotted point by point). For "manual" controls and cases will be assigned automatically; then controls and cases will be swapped if median(controls) > median(cases).
b) enter the title of the plot and check if the parameter name should be in the title as well.
c) enter the x-axis label and check if the name of negative control group should be in the x-axis as well
d) enter the y-axis label
e) set aspect ratio (height/width), depends on pixel dimensions in "output option" tab (default:=700/1000)
f) scale the legend (default:=1) and set position
######
$$$TEMPLATE_DESC$$$
#1.0 Parameter selection
# a) Define your numerical attribute of interest
parameter = c()
# b) Define the treatment column, needs further development
category = c()
# c) Define the controls group factor (negative controls)
# d) Define the case group factor (positve controls)
caseVar = c()
# e) Options for visualization
plotMethod = c()
controlCaseDirection = c()
legendPosition = c()
remove NAs -> sort
data <- na.omit(rbind(subset(kIn,kIn[,category] == controlVar, select = c(parameter[j], category)), subset(kIn,kIn[,category] == caseVar[i], select = c(parameter[j], category))))
if (median(data[which(data[,category] == controlVar),parameter[j]], na.rm = TRUE) > median(data[which(data[,category] == caseVar[i]),parameter[j]], na.rm = TRUE) || (controlCaseDirection != "automatic")) {
data <- data[order(data[,parameter[j]], decreasing = FALSE),]
} else {
#data is sorted the other way, because control bigger values bigger that case values. Then set * to legend curve and add title to lagend
data <- data[order(data[,parameter[j]], decreasing = TRUE),]
controlCaseResorted <- "*"
legendTitle <- "* = control & case inverted"
}
#define length of steps to walk in x and y per data point
xLength <- 1/(length(which(data[,category] == controlVar))-1)
yLength <- 1/(length(which(data[,category] == caseVar[i]))-1)
#initalize first point, then draw steps
previousPoint <- c(0,0)
for (d in 1:length(data[,1])){
if (data[d,category] == controlVar){
currentPoint <- c(previousPoint[1]+xLength,previousPoint[2])
} else {
currentPoint <- c(previousPoint[1],previousPoint[2]+yLength)
}
lines(c(previousPoint[1],currentPoint[1]),c(previousPoint[2],currentPoint[2]), type = "l", col = colVector[(j-1)*length(caseVar)+i])
previousPoint <-currentPoint
}
} else {
#if plotMethod == "auto"
#calculate the ROC object
currentRoc <- roc(controls = kIn[which(kIn[,category] == controlVar),parameter[j]], cases = kIn[which(kIn[,category] == caseVar[i]),parameter[j]], percent=FALSE)
if ((i == 1) && (j == 1)) {
#set up plot for first iteration, take first color
plot.roc(currentRoc, col=colVector[1], legacy.axes=TRUE, main=titleLabel, xlab=xAxisLabel, ylab=yAxisLabel, asp=aspRatio)
#define a variable for legend vector
legendVector <- NULL
} else {
#add lines to plot, colors: e.g. 0*2+1, 0*2+2, 1*2+1, 1*2+2, 2*2+1, ...
lines.roc(currentRoc, col=colVector[(j-1)*length(caseVar)+i])
}
}
#make legend vector: only if ONE parameter use the "cases", else use combination "parameter - cases" as legend
if (length(parameter) == 1){
legendVector[i] <- paste(caseVar[i], controlCaseResorted,sep="")
} else {
legendVector[(j-1)*length(caseVar)+i] <- paste(parameter[j], " - ", caseVar[i], controlCaseResorted, sep="")
}
}
}
legend(legendPosition, legendVector, lty=1, col=colVector[1:length(legendVector)], cex=legendScale, title=legendTitle)
}
]]>
########################################################################################
# name: Correlogram
# author: Holger Brandl
# category: relations
# preview: correlogram.png
Produces a graphical display of a correlation matrix, called a correlogram. The cells of the matrix can be shaded or colored to show the correlation value.
Source: http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=148
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
# a) Define which parameters you would like to visualize
params = which(names(kIn) %in% c());
# a) (optional) title
title=;
# 2. r-code
########################################################################################
# name: Correlogram (colored ellipses)
# author: Holger Brandl
# category: relations
# preview: ellipse-correlogram.png
Produces a graphical display of a correlation matrix, called a correlogram. The cells of the matrix can be shaded or colored to show the correlation value.
Source: http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=149
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
# a) Define which parameters you would like to visualize
params = which(names(kIn) %in% c());
# 2. r-code
########################################################################################
# name: Correlogram with p-values
# author: Holger Brandl
# category: relations
# preview: correlation-scattermatrix+pvalues.png
Visualization of a Correlation Matrix. On top the (absolute) value of the correlation plus the result of the cor.test as stars. On botttom, the bivariate scatterplots, with a fitted line.
Source: http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=137
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
# a) Define which parameters you would like to visualize
params = which(names(kIn) %in% c());
# 2. r-code
########################################################################################
# name: density-scatter-matrix
# author: Felix Meyenhofer
# category: relations
# preview: density-scatter-matrix.png
Displays a scatter matrix where the color code reflect the density of points.
The densities are log2-scaled.
Parameter:
Grouping column: cathegorical column that associates the observation to a group.
Feature space: a set of variables (columns) where each feature is plotted in a
scatter plot against all other features.
######
$$$TEMPLATE_DESC$$$
# a) Define the feature space
numericColumns= c();
# b) the title of the plot
########################################################################################
# name: Grouped scatter-matrix
# author: Felix Meyenhofer, modified by Martin Stoeter
# category: relations
# preview: grouped-scatter-matrix.png
Diplays a scatter matrix where all the groups found in the grouping column get their own color.
Parameter:
1) Grouping column: select a categorical column that contains the factors/groups.
2) Feature space: select numerical variables where each variable is plotted in a scatter plot against all other variables.
3) Title: enter a title
4) Layout:
- Alpha value: define the alpha value of the points. The more data the lower you can set this value.
- Select color palette for plot.
- Select if background should be white.
- If color palette "manual" is used then select colors for each group (in alphabetical order of groups)
- see here for colors: http://research.stowers-institute.org/efg/R/Color/Chart/ColorChart.pdf
######
$$$TEMPLATE_DESC$$$
#1.0 Parameter selection
# a) Define the grouping column
groupColumn= ;
# b) Define the feature space
numericColumns= c();
# c) the title of the plot
# d) Alpha value
# e) Define the colour of fill or line
colorPalette = ;
# f) Define the colour of fill or line
setBkgWhite = ;
# g) Select manual colors for groups (number of colors and groups must be the same!)
setColorPaletteManual = ;
colorPaletteVector = c()
length(unique(kIn[,groupColumn]))) colorPaletteVector <- colorPaletteVector[1:length(unique(kIn[,groupColumn]))]
}
#2.3 calculate
completeDF <- kIn[complete.cases(kIn[,params]),]
dat <- data.frame(t(combn(params, 2)))
names(dat) <- c("X","Y")
clevels <- unique(c(as.character(dat$X),as.character(dat$Y)))
dat$X <- factor(dat$X, levels = clevels)
dat$Y <- factor(dat$Y, levels = clevels)
dat <- ddply(dat, c('X', 'Y'), function(d) {
xd <- as.character(d$X[1])
yd <- as.character(d$Y[1])
data.frame(x = completeDF[,xd], y = completeDF[,yd], group = completeDF[,groupColumn])
})
#2.4.1 layout plot
theme <- theme(panel.background = theme_rect(fill = "gray95"),
panel.grid.minor = theme_blank(),
legend.background = theme_rect(fill = "gray85"),
axis.title.x = element_text(colour = NA),
axis.title.y = element_text(colour = NA))
#2.4.2 plot data
p <- ggplot(dat, aes(x = x, y = y, colour = group)) + geom_point(alpha=alphaValue) + facet_grid(Y ~ X, scales='free') + theme
switch(which(colorPalette == c('standard','clarity','Spectral','manual')), {
}, { #standard
if(length(unique(dat[,"group"])) < 9) p <- p + scale_colour_brewer("clarity")}, {
if(length(unique(dat[,"group"])) < 11) p <- p + scale_colour_brewer(pal = "Spectral")}, {
p <- p + scale_colour_manual(values = colorPaletteVector)}
)
#plot title
p <- p + ggtitle(plotTitle)
#set background on/off
if (setBkgWhite) p <- p + theme_bw()
print(p)
]]>
########################################################################################
# name: Group means parallel-plot
# author: Holger Brandl, Antje Niederlein, Martin Stoeter
# category: screening/profiles
# preview: group_means_parallel_plot.png
A parallel plot (aka profile plot) of means of different groups with errors bars. If robust statistics is checked the median and mad will be used instead of mean and sd. The y-axis limits are calculated from the input data, optional you can set the limits manually or calculate them from the plot data using min and max plotted valued (auto scale). Horizontal lines can be plotted optionally.
Inputs
1) a grouping variable
2) a selection of assay parameters
3) option: use robust statistics
4) option: set the y-axis limits or allow auto scale (on min and max plot value) on y-axis
5) option: draw horizontal lines at two y values
6) option: label of y-axis
7) option: add title
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
# a) define your grouping variable
catVar =
# b) define your parameters of interest
parameters = c()
# c) use robust statistics?
# d) set y axis scale
# e) add horizontal lines
# f) define y-axis label
# g) define a title for the plot
########################################################################################
# name: Group means parallel-plot with layout options
# author: Holger Brandl, Antje Niederlein, Martin Stoeter
# category: screening/profiles
# preview: group_means_parallel_plot.png
A parallel plot (aka profile plot) of means of different groups with or without errors bars.
If robust statistics is checked the median and mad will be used instead of mean and sd.
The y-axis limits are calculated from the input data, optional you can set the limits manually or calculate them from the plot data using min and max plotted valued (auto scale).
Horizontal lines can be plotted optionally.
Inputs
1) a grouping variable
2) a selection of assay parameters
3) option: use robust statistics
Layout Options:
- check to use robust statistics and to plot error bars
- select background/theme and set general font size in plot (default = 14)
- set size and alpha value (transparency) of lines and error bars (default = [0.5,0.1] and [0.5,0.5])
- give plot title and title factor (default = 1.2)
- x-axis test: angle, text size factor for x-/y-axis (default = 0.8)
- y-axis title, axis title size factor (default = 1.0)
- adjust y-axis scale (enter min + max)
- give legend title, adjust position (fixed position outside diagram or free(range:0-1): [0.1,0.9] = top-left) and legend title/text size factor(default = 0.8)
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
# a) define your grouping variable
catVar =
# b) define your parameters of interest
parameters = c()
# c) use robust statistics?
#diagram options
pointLineSize = as.numeric(c())
alphaValue = as.numeric(c())
hLines = as.numeric(c())
plotTheme =
plotTextSize = as.numeric(c())
plotTitleSize = as.numeric(c())
xAngle = as.numeric(c())
axisTextSizeFactor = as.numeric(c())
axisTitleSizeFactor = as.numeric(c())
yAxisScale = as.numeric(c())
legendPosition =
useLegendCoordinate =
legendCoordinate = as.numeric(c())
legendTitle =
legendTextSizeFactor = as.numeric(c())
rotateLegend =
40)) pointLineSize[1] <- 0.5
if (is.na(pointLineSize[2]) | (pointLineSize[2] < 0) | (pointLineSize[2] > 10)) pointLineSize[2] <- 0.1
if (is.na(alphaValue[1]) | (alphaValue[1] < 0) | (alphaValue[1] > 1)) pointLineSize[1] <- 0.5
if (is.na(alphaValue[2]) | (alphaValue[2] < 0) | (alphaValue[2] > 1)) pointLineSize[2] <- 0.5
if (is.na(plotTitle)) plotTitle <- NULL #default if no title is given
if (is.na(plotTextSize[1]) | (plotTextSize[1] < 0) | (plotTextSize[1] > 40)) plotTextSize[1] <- 14
if (is.na(plotTitleSize[1]) | (plotTitleSize[1] < 0) | (plotTitleSize[1] > 5)) plotTitleSize[1] <- 1.2
if (is.na(yAxisLabel)) yAxisLabel <- NULL
if (is.na(axisTextSizeFactor[1]) | (axisTextSizeFactor[1] < 0) | (axisTextSizeFactor[1] > 5)) axisTextSizeFactor[1] <- 0.8
if (is.na(axisTextSizeFactor[2]) | (axisTextSizeFactor[2] < 0) | (axisTextSizeFactor[2] > 5)) axisTextSizeFactor[2] <- 0.8
if (is.na(axisTitleSizeFactor[1]) | (axisTitleSizeFactor[1] < 0) | (axisTitleSizeFactor[1] > 5)) axisTitleSizeFactor[1] <- 1
if (is.na(axisTitleSizeFactor[2]) | (axisTitleSizeFactor[2] < 0) | (axisTitleSizeFactor[2] > 5)) axisTitleSizeFactor[2] <- 1
if (is.na(yAxisScale[1]) | is.na(yAxisScale[2])) yAxisScale <- NULL
if (is.na(legendTitle)) legendTitle <- catVar #default if no title is given
if (is.na(legendCoordinate[1]) | is.na(legendCoordinate[2]) | (legendCoordinate[1] < 0) | (legendCoordinate[1] > 1) | (legendCoordinate[2] < 0) | (legendCoordinate[2] > 1)) useLegendCoordinate <- FALSE
if (is.na(legendTextSizeFactor[1]) | (legendTextSizeFactor[1] < 0) | (legendTextSizeFactor[1] > 5)) legendTextSizeFactor[1] <- 0.8
if (is.na(legendTextSizeFactor[2]) | (legendTextSizeFactor[2] < 0) | (legendTextSizeFactor[2] > 5)) legendTextSizeFactor[2] <- 0.8
if (xAngle == 0 ) xAxisAjust <- c(0.5,1.0) #xAxisAjust = c(hjust,vjust)
if (xAngle == 45) xAxisAjust <- c(1.0,1.0)
if (xAngle == 90) xAxisAjust <- c(1.0,0.5)
useKNIMEColors <- FALSE
if(colorPalette == "KNIME colors") useKNIMEColors <- FALSE #set this to TRUE once KNIME colors is tested
# for brewer palettes check possible values
colourCol <- catVar
nFactors <- length(colourCol)
brewerTable <- do.call("cbind", brewer.pal.info)
rownames(brewerTable) <- rownames(brewer.pal.info)
if (colorPalette %in% rownames(brewerTable) && !useKNIMEColors) {
if (brewerTable[which(rownames(brewerTable) == colorPalette),"maxcolors"] < nFactors) colorPalette <- "ggplot default"
} else {
warningMessage <- paste("Color set '", colorPalette, "' cannot be used for ", nFactors, " different values. Color palette is reset to ggplot default", sep = "")
warning(warningMessage)
colorPalette <- "ggplot default"
}
if (useKNIMEColors) {
# check if color model is joined to data table
if (!length(which(c("R","G","B","A") %in% names(kIn))) == 4) {
colorPalette <- "standard"
warning("KNIME colors not available in input table, standard palette is used instead")
# if yes, generate color table from KNIME colors
} else {
# check whether colors belong to grouping factor
colorTable <- lapply(factors, FUN = function(x) {
subdata <- subset(kIn, kIn[, factorName] == x, select = c(R, G, B, A, RGBA), drop = FALSE)
if(length(unique(subdata$RGBA)) > 1) stop("KNIME color model does not fit to selected factor column")
subdata[1,]
})
# create color vector
names(colorTable) <- factors
colorTable <- do.call("rbind", colorTable)
factorColors <- rgb(colorTable$R, colorTable$G, colorTable$B, colorTable$A, max = 255)
names(factorColors) <- factors
}
}
#2.3 calculate
#define functions/methods to calculate central values and error bars
if (robust == FALSE) {
#none robust statistics
parameterLabel = "Parameters (aggregation: mean & sd)"
centralValue <- function(x){
x.mean <- mean(x, na.rm = TRUE)
return(x.mean)
}
errorUpper <- function(x){
x.mean <- mean(x, na.rm = TRUE)
x.sd <- sd(x, na.rm = TRUE)
return(x.mean + x.sd)
}
errorLower <- function(x){
x.mean <- mean(x, na.rm = TRUE)
x.sd <- sd(x, na.rm = TRUE)
return(x.mean - x.sd)
}
} else {
#robust statistics
parameterLabel = "Parameters (aggregation: median & mad)"
centralValue <- function(x){
x.median <- median(x, na.rm = TRUE)
return(x.median)
}
errorUpper <- function(x){
x.median <- median(x, na.rm = TRUE)
x.mad <- mad(x, na.rm = TRUE)
return(x.median + x.mad)
}
errorLower <- function(x){
x.median <- median(x, na.rm = TRUE)
x.mad <- mad(x, na.rm = TRUE)
return(x.median - x.mad)
}
}
classesOfInterest <- levels(factor(kIn[,catVar]))
# create a subset ony containing entries with classes of interest and parameters of interest
subData <- subset(kIn, get(catVar) %in% classesOfInterest)
subData <- subData[, c(catVar,parameters)]
# set rowID as extra column for reshaping
#subData$id <- rownames(subData)
#calculate auto y-axis scale
if (yAxisAutoScale) {
minMax <- list()
for (i in 1:length(classesOfInterest)) {
minMax[[i]] <- c(min(apply(subset(subData, subData[,catVar] == classesOfInterest[i], select = parameters), 2, errorLower)), max(apply(subset(subData, subData[,catVar] == classesOfInterest[i], select = parameters), 2, errorUpper)))
}
minMax <- do.call("rbind", minMax)
yAxisScale <- c(min(minMax), max(minMax))
#increase the plot area
yAxisScale <- c(yAxisScale[1] - range(yAxisScale[1], yAxisScale[2]) / 20, yAxisScale[2] + range(yAxisScale[1], yAxisScale[2]) / 20)
}
# reshape data for ggplot
plotData <- melt(subData, id = catVar)
#2.4.1 plot data
p <- ggplot(plotData, aes(x = variable, y = value, colour = get(catVar), group = get(catVar)))
#2.4.2 layout plot
#general
if(plotTheme == "grey"){
p <- p + theme_grey(base_size=plotTextSize[1])
} else {
p <- p + theme_bw(base_size=plotTextSize[1])
}
p <- p + coord_cartesian(ylim = yAxisScale)
#error bars and horizontal lines
p <- p + stat_summary(fun.y = centralValue, geom = "line", size = pointLineSize[1], alpha = alphaValue[1])
if(plotErrorBars == TRUE) p <- p + stat_summary(fun.ymax = errorUpper, fun.ymin = errorLower, geom = "errorbar", width = pointLineSize[2], alpha = alphaValue[2])
if (!is.na(hLines[1])) p <- p + geom_hline(yintercept = hLines[1])
if (!is.na(hLines[2])) p <- p + geom_hline(yintercept = hLines[2])
#title options
p <- p + ggtitle(plotTitle)
p <- p + theme(plot.title = element_text(size = plotTextSize[1] * plotTitleSize[1]))
#axis label options
#p <- p + scale_x_discrete(name = xFactorCol)
p <- p + labs(x = parameterLabel, y = yAxisLabel, colour = catVar)
p <- p + theme(axis.title.x = element_text(size = plotTextSize[1] * axisTitleSizeFactor[1]), axis.title.y = element_text(size = plotTextSize[1] * axisTitleSizeFactor[2]))
p <- p + theme(axis.text.x = element_text(angle = xAngle, hjust = xAxisAjust[1], vjust = xAxisAjust[2], size = plotTextSize[1] * axisTextSizeFactor[1]), axis.text.y = element_text(size = plotTextSize[1] * axisTextSizeFactor[2]))
p <- p + scale_y_continuous(limits = yAxisScale, name = yAxisLabel) #use e.g. limits = c(0,100)
#legend
if(rotateLegend) {
p <- p + scale_color_discrete(name = legendTitle, guide = guide_legend(direction = "horizontal", title.position = "top", label.position="bottom", label.hjust = 0.5, label.vjust = 0.5, label.theme = element_text(angle = 90)))
} else {
p <- p + scale_color_discrete(name = legendTitle)
}
p <- p + theme(legend.title = element_text(size = plotTextSize[1] * legendTextSizeFactor[1], face = "bold"), legend.text = element_text(size = plotTextSize[1] * legendTextSizeFactor[2]))
if (useLegendCoordinate) {
p <- p + theme(legend.position = legendCoordinate, legend.background = element_rect(fill = "transparent",colour = NA))
} else {
p <- p + theme(legend.position = legendPosition)
}
# color settings
colorPaletteVector <- c("red", "blue", "darkgreen", "orange")
#p <- p + scale_colour_manual(values = colorPaletteVector)
if(useKNIMEColors) {
p <- p + scale_color_manual(name = catVar, labels = factors, values = factorColors)
p <- p + scale_fill_manual(name = catVar, labels = factors, values = factorColors)
} else {
if(colorPalette == "ggplot default") {
p <- p + scale_color_discrete(name = catVar)
p <- p + scale_fill_discrete(name = catVar)
} else {
p <- p + scale_color_brewer(name = catVar, palette = colorPalette)
p <- p + scale_fill_brewer(name = catVar, palette = colorPalette)
}
}
print(p)
]]>
########################################################################################
# name: Parallel plot grid by factor
# author: Holger Brandl, Antje Niederlein, Martin Stoeter
# category: screening/profiles
# preview: parallel-plot-grid-by-factors.png
A grid of parallel plots where each plot displays a parameter profile for all data points belonging to the same group. Additionally the mean of the data set is shown including error-bars. If robust statistics is checked the median and mad will be used instead of mean and sd.
Inputs:
1) a grouping variable
2) a selection of assay parameters
3) option: use robust statistics
4) option: scale of y-axis (default, use fixed values, auto-scale (plot area = +/-5% of min/max))
5) option: set number of columns in grip plot (default, set automatic)
6) option: draw horizontal lines at two y values
7) option: label of y-axis
8) option: add title
######
$$$TEMPLATE_DESC$$$
# 1.0 Parameter selection
# a) define your grouping variable
# b) define your parameters of interest
parameters = c()
# c) use robust statistics?
# d) set y axis scale
# d2) set grid colums
# e) add horizontal lines
# f) define y-axis label
# g) define a title for the plot
########################################################################################
# name: QQ-Plot grid
# author: Holger Brandl, Martin Stoeter
# category: screening/qc
# preview: qq-plot.png
Creates a grid of qq-plots (with respect to normal distribution) which allow to visually determine which parameters follow a normal distribution
- to use a flow variable check box and type in variable name using the format: FLOWVAR(variable name)
- use the R-snippet template "Shapiro-Wilk Normality Test (QQ-Plot)" to get the statistics
######
$$$TEMPLATE_DESC$$$
#1. Parameter selection
#Select the parameter of interest
selReadouts = c()
1, 2, 1)
par(mfrow = c(numGridRows, ceiling(length(selReadouts) / numGridRows)))
#4.2 plot data
# iterate over all parameters and create plots for all of them
lapply(selReadouts, FUN = function (param) {
plotVar = eval(parse(text = paste("kIn$\"", param, "\"", sep = '')))
#remove NA (shapiro test allows NA but data has to have 3 - 5000 non-missing-values)
plotVar <- plotVar[which(!is.na(plotVar))]
#plot
qqnorm(plotVar, main = param)
qqline(plotVar)
# if there are more than 5000 data points, run test on a subset
if(length(plotVar) > 5000) {
plotVar <- sample(plotVar, 5000)
}
# do the test and add the p-value to the plot
testresult <- shapiro.test(plotVar)
# use relative positioning of the text plotting (http://www.mail-archive.com/r-help@r-project.org/msg15119.html)
usr <- par("usr") # get user coordinates
par(usr = c(0, 1, 0, 1)) # new relative user coordinates
text(0.75, 0.05, format(testresult$p.value, scientific=TRUE, digits=4), cex=1.5, col=2) # if that's what you want
par(usr = usr) # restore original user coordinates
})
]]>
########################################################################################
# name: Screen Scatter Plot Grid / Trend Plot (color model, treatment column)
# author: Holger Brandl, Martin Stoeter
# category: screening/qc
# preview: screenscattergrid.png
This plot is also known as trend- or sequence-plot ("High-throughput screening in drug discovery, Hueser, 2006, Wiley")
This scatter plot displays all wells of a screen. The bulk data is plotted in grey circles (usually annotated as "library" in categorial column) and all other categories are plotted in different colors and shapes. If colors were assigned to categories in KMIME and attached to the data table (Color Manager -> Extract Colors -> Join), R will use the R, G, B, A columns to generate the colors for the categories. Multiple parameters are plotted as grid of subplots.
To use a flow variable check box and type in variable name using the format: FLOWVAR(variable name) (doesn't work like this for grid of subplots)
Further options are:
- adjust y-axis: default = min-max +/- 5%; optional use of quantiles = (lower quantile * lower scale factor) until (upper quantile * upper scale factor);
extended range factor: e.g. 0.05 extends y-axis by +/- 5%
- use the scale factors to adjust a) point sizes of bulk and b) rest data as well as c) the legend size
- horizontal dashed and solid lines can be plotted
- title can be changed
Hint: use "Nominal row filter" node to select the categories to plot (former treatment column) and "Sorter" node to define well index.
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
# a) Define column with categorial values
treatments = c();
# b) Define which parameter you would like to visualize
params = c()
# c) Options for visualization
= 1)) yAxisScaleFactors[1] <- 0
if (is.na(yAxisScaleFactors[2]) | (yAxisScaleFactors[2] <= 0) | (yAxisScaleFactors[2] > 1)) yAxisScaleFactors[2] <- 1
if (is.na(yAxisScaleFactors[3])) yAxisScaleFactors[3] <- 1
if (is.na(yAxisScaleFactors[4])) yAxisScaleFactors[4] <- 1
if (is.na(yAxisScaleFactors[5]) | (useDefaultyAxisScale)) yAxisScaleFactors[5] <- 0.05
#2.3 calculate
if (useFlowVar) params <- flowVariable
#2.4.1 layout plot
if (useKNIMEcolors) {
factorColors <- rgb(colorTable$R, colorTable$G, colorTable$B, colorTable$A, names = NULL, max = 255) #uses KMINE colors (Color Manager -> Extract Colors -> Join color table)
} else {
factorColors <- colors()[c(185,121,150,100,48,490,98, round(runif(50,min=1, max = 600)))] #default definition of colors
}
factorSymbols = c(1,rep(19,4),rep(17,4),rep(15,4),rep(18,4),rep(22,50)); #definition of symbols see help pch
numGridRows = ifelse(length(params) > 1, 2, 1);
par(mfrow = c(numGridRows, ceiling(length(params) / numGridRows)))
# iterate over all parameters and create plots for all of them
lapply(params, FUN = function (param) {
if (useJoinParameterToTitle) title <- paste(title, names(kIn[param]))
#2.4.2 plot data
# iterate over categories
for(factor in factors){
index = which(factors == factor)
#set y-axis scale
if (useDefaultyAxisScale) {
yAxisScale <- extendrange(kIn[,param], f = yAxisScaleFactors[5])
} else {
yAxisScale <- c(quantile(kIn[, param], na.rm = TRUE, names = FALSE, yAxisScaleFactors[1]), quantile(kIn[, param], na.rm = TRUE, names = FALSE, yAxisScaleFactors[2])) * c(yAxisScaleFactors[3], yAxisScaleFactors[4])
#check if data is there/yAxisScales are numbers (otherwise plot fails) then do subplot without data (no points are plotted)
if ((is.na(yAxisScale)[1] == TRUE) || (is.na(yAxisScale)[2] == TRUE)
|| (is.infinite(yAxisScale)[1] == TRUE) || (is.infinite(yAxisScale)[2] == TRUE)) {
yAxisScale <- extendrange(kIn[,param], f = yAxisScaleFactors[5])
} else {
yAxisScale <- extendrange(r = yAxisScale, f = yAxisScaleFactors[5])
}
}
if(index == 1){ #is it bulk data?
plot(which(kIn[,catVar] == factor), kIn[which(kIn[,catVar] == factor), param], ylim = yAxisScale, main = title, xlab = "well index", ylab = names(kIn[param]), col = factorColors[index], pch = factorSymbols[index], xlim = c(1,nrow(kIn)), cex = scaleFactors[1])
} else {
points(which(kIn[,catVar] == factor), kIn[which(kIn[,catVar] == factor), param], col = factorColors[index], pch = factorSymbols[index], bg = factorColors[index], cex = scaleFactors[2])
}
}
# adds horizontal lines
abline(h = hlines[c(1,3)], lty = 2)
abline(h = hlines[2], lwd = 1.5)
# add the legend
legend("topright", pch= factorSymbols[1:length(factors)], factors, col = factorColors, pt.bg = factorColors, cex = scaleFactors[3])
})
]]>
########################################################################################
# name: Factorized histogram/density plot grid, KNIME colors
# author: Holger Brandl, modified by Martin Stoeter
# category: basic/histograms
# preview: factorized_density_plot_grid.png
Creates a grid of density plots for selected columns and plots densities for each factor (group).
1) Select numerical variables. Each variable will result in a subplot. Multiple parameters are plotted as grid of subplots.
- To use a flow variable check box and type in variable name using the format: FLOWVAR(variable name) (doesn't work like this for grid of subplots)
2) Select a column that contains the factors/groups of densities to plot.
Options for visualization:
a) how to plot the data (filled densities, line densities and/or histogram).
b) adjust transparency for filled and line thickness for line densities, adjust number of bins
c) color palette that is used (KNIME colors: if colors were assigned to categories in KMIME and attached to the data table (Color Manager -> Extract Colors -> Join), R will use the R, G, B, A columns to generate the colors for the categories)
c) Select if background should be white.
d) optional title, font size of plot can de defined
e) x-axis title can be customized, and relative font size of axis title and label for x- and y-axis can be specified
f) x-axis limits can be set and where global or free axis ranges are applied (free scales) for 2D grid
e) optional add horiziontal and/or vertical lines with certain type, color and line size (no legend title = legend not diplayed)
f) adjust legend position, text size and legend title
######
$$$TEMPLATE_DESC$$$
# RGG-Configuration ==============================================================================================
# a) Define your numerical attribute of interest
params = c()
# b) Define the grouping factor
# c) Options for visualization
useParameterXnameAsAxisLabel =
axisTextSizeFactorX = as.numeric(c())
axisTextSizeFactorY = as.numeric(c())
useManualXaxisScale =
xAxisScale = as.numeric(c())
free.xscales =
lineTypeH =
lineOptionsH = c()
lineTypeV =
lineOptionsV = c()
# legend configureation
legendPosition =
useLegendCoordinate =
legendCoordinate = as.numeric(c())
legendTitle =
legendTextSizeFactor = as.numeric(c())
rotateLegend =
# End of RGG-Configuration ==============================================================================================
5)) axisTextSizeFactorX[1] <- 1.0
if (is.na(axisTextSizeFactorX[2]) | (axisTextSizeFactorX[2] < 0) | (axisTextSizeFactorX[2] > 5)) axisTextSizeFactorX[2] <- 0.8
if (is.na(axisTextSizeFactorY[1]) | (axisTextSizeFactorY[1] < 0) | (axisTextSizeFactorY[1] > 5)) axisTextSizeFactorY[1] <- 1.0
if (is.na(axisTextSizeFactorY[2]) | (axisTextSizeFactorY[2] < 0) | (axisTextSizeFactorY[2] > 5)) axisTextSizeFactorY[2] <- 0.8
if (is.na(xAxisScale[1]) | is.na(xAxisScale[2])) xAxisScale <- NULL
# set paramters to flow variable if required
if (useFlowVar) params <- flowVariable
useKNIMEColors <- FALSE
if(colorPalette == "KNIME colors") useKNIMEColors <- TRUE
# for brewer palettes check possible values
nFactors <- length(factors)
t_set1 <- colorPalette == "Set1" & nFactors > 9
t_set2 <- colorPalette == "Set2" & nFactors > 8
t_set3 <- colorPalette == "Set3" & nFactors > 12
t_accent <- colorPalette == "Accent" & nFactors > 8
t_dark2 <- colorPalette == "Dark2" & nFactors > 8
t_paired <- colorPalette == "Paired" & nFactors > 12
if(t_set1 | t_set2 | t_set3 | t_accent | t_dark2 | t_paired) {
warningMessage <- paste("Color set '", colorPalette, "' cannot be used for ", nFactors, " different values. Color palette is reset to ggplot default", sep = "")
warning(warningMessage)
colorPalette <- "ggplot default"
}
# color model checks: is it available? is it defined for the grouping column?
if(useKNIMEColors && !exists("kIn.color.model")) {
stop("No KNIME color model provided. Script was stopped!")
useKNIMEColors <- FALSE
}
colourCol <- factorName
if(useKNIMEColors && names(kIn.color.model[1]) != colourCol) {
stop(paste("KNIME color model is different (", names(kIn.color.model[1]), ") from selected color grouping column (", colourCol, ") in template. Script was stopped!"))
useKNIMEColors <- FALSE
}
if(useKNIMEColors) {
kIn.color.model$color <- as.character(kIn.color.model$color)
colourCol <- names(kIn.color.model)[1]
factorColors <- kIn.color.model[,2]
names(factorColors) <- kIn.color.model[,1]
}
# reshape data
paramIdx <- which(names(kIn) %in% params)
plotData <- melt(kIn, id.vars = factorIndex, measure.vars = paramIdx)
names(plotData)[names(plotData) == factorName] <- "group"
# handle missing values
if (ignoreMissingValues) {
plotDataRowCount <- length(plotData[,1])
plotData <- na.omit(plotData)
if (plotDataRowCount > length(plotData[,1]))
warning(paste("WARNING: excluded ", length(plotData[,1]) - plotDataRowCount ," missing value(s)."))
} else {
if (length(plotData[,1]) > length(na.omit(plotData)[,1]))
stop("Missing values found: please select 'ignore missing values' in template or check your data set!")
}
groupedData <- dlply(plotData, .(variable))
groupedBinWidth <- llply(groupedData, .fun = function(data, nBins) {
r <- range(data$value, na.rm = TRUE, finite = TRUE)
r <- extendrange(r = r, f = 0.0) #why extend by 0.0? makes no sense
widthOfBins = (r[2] - r[1])/nBins
if (is.na(widthOfBins) || is.infinite(widthOfBins) || (widthOfBins <= 0)) widthOfBins <- NULL
widthOfBins
}, nBins = numberOfBins - 1) # numberOfBins -1, because the actual number of bins would be one more
densData <- dlply(plotData, .(variable, group), .fun = function(subData){
param <- subData$variable[1]
group <- subData$group[1]
d <- density(subData$value)
bw <- groupedBinWidth[[param]]
data.frame(x = d$x, y = d$y * nrow(subData) * bw , group = group, variable = param)
})
hLay <- mapply(function(x, b) geom_bar(aes(x = value, fill = group), position = position_dodge(), data = x, binwidth = b, alpha = alphaValue, show.legend = FALSE),
groupedData, groupedBinWidth)
dLay <- mapply(function(data) geom_density(data = data, aes(x = x, y = y), stat = "identity", fill = NA, size = lineSize, alpha = alphaValue),
densData)
# the actual plot
m <- ggplot(plotData, aes(x = value, color = group, fill = group, group = group))
if(plotHistogram) {
m <- m + dLay
m <- m + hLay
} else {
if(plotDensityMode == "filled curves") m <- m + geom_density(alpha = alphaValue)
if(plotDensityMode != "filled curves") m <- m + geom_density(fill = NA, size = lineSize, alpha = alphaValue)
}
if(useKNIMEColors) {
m <- m + scale_color_manual(name = factorName, breaks = factors, labels = factors, values = factorColors)
m <- m + scale_fill_manual(name = factorName, breaks = factors, labels = factors, values = factorColors)
} else {
if(colorPalette == "ggplot default") {
m <- m + scale_color_discrete(name = factorName)
m <- m + scale_fill_discrete(name = factorName)
} else {
m <- m + scale_color_brewer(name = factorName, palette = colorPalette)
m <- m + scale_fill_brewer(name = factorName, palette = colorPalette)
}
}
if(!is.na(title)) m <- m + ggtitle(label = title)
m <- m + theme(legend.position = legendPosition)
if(!setBkgWhite) { m <- m + theme_gray(base_size = plotTextSize)
} else { m <- m + theme_bw(base_size = plotTextSize) }
m <- m + facet_wrap( ~ variable, scales = free.scales)
#axis label options
if (useParameterXnameAsAxisLabel) m <- m + labs(x = xAxisLabel)
m <- m + theme(axis.title.x = element_text(size = plotTextSize[1] * axisTextSizeFactorX[1]), axis.title.y = element_text(size = plotTextSize[1] * axisTextSizeFactorY[1]))
m <- m + theme(axis.text.x = element_text(size = plotTextSize[1] * axisTextSizeFactorX[2]), axis.text.y = element_text(size = plotTextSize[1] * axisTextSizeFactorY[2]))
#if(useManualYaxisScale) m <- m + coord_cartesian(ylim = yAxisScale)
if(useManualXaxisScale) m <- m + coord_cartesian(xlim = xAxisScale)
#additional lines like horizontal or vertical
# debugging work in progress.... MS
#lineTypeH = "blank"
#lineOptionsH[4]= "lines "
#lineOptionsH[4]= ""
#lineTypeH = "dotted"
showLegendH <- FALSE # no legend will be shown for Hline, will be set to NA if title is given... see below...
if (lineTypeH != "blank") {
if (nchar(lineOptionsH[4]) > 0) { # if no legend title is given for Hline, then dont show legend = FALSE
showLegendH <- NA # must be NA and not TRUE, otherwise Hline legend will be plotted on data legend
}
if(!is.na(showLegendH) & lineTypeV != "blank") {
m <- m + geom_hline(linetype = lineTypeH, yintercept = as.numeric(lineOptionsH[1]), color = lineOptionsH[2], size = as.numeric(lineOptionsH[3]))
} else {
m <- m + geom_hline(aes(yintercept = as.numeric(lineOptionsH[1]), linetype = lineTypeH), show.legend = showLegendH, color = lineOptionsH[2], size = as.numeric(lineOptionsH[3]))
m <- m + scale_linetype_manual(name = lineOptionsH[4], values = c(lineTypeH), guide = guide_legend(order=2), labels = c(lineOptionsH[1])) # , override.aes = list(color = c(lineOptionsH[2]))
}
#m <- m + geom_text(aes(0,as.numeric(lineOptionsH[1]),label = as.numeric(lineOptionsH[1]), vjust = -1))
#m <- m + scale_y_continuous(breaks = sort(c(ggplot_build(m)$layout$panel_ranges[[1]]$y.major_source, as.numeric(lineOptionsH[1]))))
}
# debugging
#lineTypeV = "blank"
#lineOptionsV[4]= ""
if (lineTypeV != "blank") {
if(is.na(showLegendH)) { # if legend is plotted for Hline
m <- m + geom_vline(linetype = lineTypeV, xintercept = as.numeric(lineOptionsV[1]), color = lineOptionsV[2], size = as.numeric(lineOptionsV[3]))
} else{
if (nchar(lineOptionsV[4]) > 0) { # if no legend title is given for Vline, then dont show legend
showLegendV <- NA # must be NA and not TRUE, otherwise Vline legend will be plotted on data legend
} else {
showLegendV <- FALSE # no legend will be shown for Hline
}
m <- m + geom_vline(aes(xintercept = as.numeric(lineOptionsV[1]), linetype = lineTypeV), show.legend = showLegendV, color = lineOptionsV[2], size = as.numeric(lineOptionsV[3]))
m <- m + scale_linetype_manual(name = lineOptionsV[4], values = c(lineTypeV), guide = guide_legend(order=3), labels = c(lineOptionsV[1]))
}
}
#legend: legend title, text style and rotation
m <- m + guides(color = guide_legend(order=1, title = legendTitle), fill = guide_legend(title = legendTitle)) + theme(legend.title = element_text(size = plotTextSize[1] * legendTextSizeFactor[1], face = "bold"), legend.text = element_text(size = plotTextSize[1] * legendTextSizeFactor[2]))
if(rotateLegend) m <- m + guides(color = guide_legend(order=1, title = legendTitle), fill = guide_legend(title = legendTitle, direction = "horizontal", title.position = "top", label.position = "bottom", label.hjust = 0.5, label.vjust = 0.5, label.theme = element_text(angle = 90)))
if (useLegendCoordinate) {
m <- m + theme(legend.position = legendCoordinate, legend.background = element_rect(fill = "transparent",colour = NA))
} else {
m <- m + theme(legend.position = legendPosition)
}
print(m)
]]>
########################################################################################
# name: Scatter Plot Grid Replicates / XY - Plot
# author: Martin Stoeter
# category: relations
# preview: xy-plot_replicates.png
This scatter plot or XY-plot can be used to plot correlating data (e.g. experimental repeats). The table must contain a column with replicate information. Then another column must contain the sample identifier, which must be unique within a replicate (e.g. platenumber::well, but not barcode!), AND the same between the replicates. For the corresponding sample identifiers the data point will be plotted on x- and y-axis (e.g. for replicates A and B, if more than two replicated are present only the first two are considered).
For multiple selected parameters plots will appear as grid plot. To use a flow variable check box and type in variable name using the format: FLOWVAR(variable name) (doesn't work like this for grid of plots)
Data point will be plotted in different colors and shapes according to the categorial value. Missing values and sample identifiers with unequal categorial values will be removed/ignored.
Layout options:
- set title or use parameter name in title
- adjust y-axis: default = min-max +/- 5%; optional use of quantiles = (lower quantile * lower scale factor) until (upper quantile * upper scale factor);
extended range factor: e.g. 0.05 extends y-axis by +/- 5%
- set legend position and size (scaling factor)
- linear regression and Pearson Correlation Coefficient can be plotted
- the bulk data term in column categorial values is plotted in grey circles (usually annotated as "library" in categorial column) and all other categories are plotted in different colors and shapes. If colors were assigned to categories in KMIME and attached to the data table (Color Manager -> Extract Colors -> Join), R will use the R, G, B, A columns to generate the colors for the categories.
- use the scale factors to adjust a) point sizes of bulk and b) other data points
Hint: use "Nominal row filter" node to select the categories to plot (former treatment column).
Trouble shooting:
a) "sampleID not unique" -> more than 1 sampleID (eg wells) per replicate
b) "not enough samples for correlation" -> sampleID for a replicate = 0 (no data to correlate)
HINT: use GroupBy[Unique concatenate with count(replicate)] on selected sampleID column, must be replicate count = 1 for each sampleID
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
# 2) select column that contains replicate annotation
# 3) select column that contains sample ID
# b) Define which parameter you would like to visualize
params = c()
# a) Define column with categorial values
treatments = c();
# c) Options for visualization
legendPosition =
legendSize =
= 1)) xAxisScaleFactors[1] <- 0
if (is.na(xAxisScaleFactors[2]) | (xAxisScaleFactors[2] <= 0) | (xAxisScaleFactors[2] > 1)) xAxisScaleFactors[2] <- 1
if (is.na(xAxisScaleFactors[3])) xAxisScaleFactors[3] <- 1
if (is.na(xAxisScaleFactors[4])) xAxisScaleFactors[4] <- 1
if (is.na(xAxisScaleFactors[5]) | (useDefaultxAxisScale)) xAxisScaleFactors[5] <- 0.05
if (is.na(yAxisScaleFactors[1]) | (yAxisScaleFactors[1] < 0) | (yAxisScaleFactors[1] >= 1)) yAxisScaleFactors[1] <- 0
if (is.na(yAxisScaleFactors[2]) | (yAxisScaleFactors[2] <= 0) | (yAxisScaleFactors[2] > 1)) yAxisScaleFactors[2] <- 1
if (is.na(yAxisScaleFactors[3])) yAxisScaleFactors[3] <- 1
if (is.na(yAxisScaleFactors[4])) yAxisScaleFactors[4] <- 1
if (is.na(yAxisScaleFactors[5]) | (useDefaultyAxisScale)) yAxisScaleFactors[5] <- 0.05
if (is.na(pearsonTextFactor) | (pearsonTextFactor <= 0) | (pearsonTextFactor > 10)) pearsonTextFactor <- 0.7
#define replicates and check: e.g A,B
repVector <- unique(kIn[, repColName])
if(length(repVector) < 2) repVector <- c(repVector[1], repVector[1])
#2.3 calculate
if (useFlowVar) params <- flowVariable
#2.4.1 layout plot
if (useKNIMEcolors) {
factorColors <- rgb(colorTable$R, colorTable$G, colorTable$B, colorTable$A, names = NULL, max = 255) #uses KMINE colors (Color Manager -> Extract Colors -> Join color table)
} else {
factorColors <- colors()[c(185,121,150,100,48,490,98, round(runif(50,min=1, max = 600)))] #default definition of colors
}
factorSymbols = c(1,rep(19,4),rep(17,4),rep(15,4),rep(18,4),rep(22,50)); #definition of symbols see help pch
numGridRows = ifelse(length(params) > 1, 2, 1);
par(mfrow = c(numGridRows, ceiling(length(params) / numGridRows)))
# iterate over all parameters and create plots for all of them
lapply(params, FUN = function (param) {
if (useJoinParameterToTitle) title <- paste(title, names(kIn[param]))
#param <- params[1]#define first (X) and second (Y) table/replicate to be merged/plotted
kInXtable <- kIn[which(kIn[,repColName] == repVector[1]),c(IDname, repColName, catVar, param)]
kInYtable <- kIn[which(kIn[,repColName] == repVector[2]),c(IDname, repColName, catVar, param)]
#check if sampleIDs are unique
if (length(unique(kInXtable[,IDname])) == length(kInXtable[,IDname]) & length(unique(kInYtable[,IDname])) == length(kInYtable[,IDname])) {
corrTable <- merge(kInXtable[,c(IDname, repColName, catVar, param)], kInYtable[,c(IDname, repColName, catVar, param)], by.x = IDname, by.y =IDname)
names(corrTable) <- c(IDname,"repX","catVarX","X","repY","catVarY","Y")
#check consitency of table after merge
corrTable <- corrTable[which(!is.na(corrTable$X) & !is.na(corrTable$Y)),]
corrTable <- corrTable[which(corrTable$catVarX == corrTable$catVarY),]
#check if XYtable match is bigger than 1
sampleIDmatch <- length(corrTable[,1])
if (sampleIDmatch > 1) {
#set x-axis scale
if (useDefaultxAxisScale) {
xAxisScale <- extendrange(kInXtable[,param], f = xAxisScaleFactors[5])
} else {
xAxisScale <- c(quantile(kInXtable[,param], na.rm = TRUE, names = FALSE, xAxisScaleFactors[1]), quantile(kInXtable[, param], na.rm = TRUE, names = FALSE, xAxisScaleFactors[2])) * c(xAxisScaleFactors[3], xAxisScaleFactors[4])
#check if data is there/xAxisScales are numbers (otherwise plot fails) then do subplot without data (no points are plotted)
if ((is.na(xAxisScale)[1] == TRUE) || (is.na(xAxisScale)[2] == TRUE) || (is.infinite(xAxisScale)[1] == TRUE) || (is.infinite(xAxisScale)[2] == TRUE)) {
xAxisScale <- extendrange(kInXtable[,param], f = xAxisScaleFactors[5])
} else {
xAxisScale <- extendrange(r = xAxisScale, f = xAxisScaleFactors[5])
}
}
#set y-axis scale
if (useDefaultyAxisScale) {
yAxisScale <- extendrange(kInYtable[,param], f = yAxisScaleFactors[5])
} else {
yAxisScale <- c(quantile(kInYtable[,param], na.rm = TRUE, names = FALSE, yAxisScaleFactors[1]), quantile(kInYtable[, param], na.rm = TRUE, names = FALSE, yAxisScaleFactors[2])) * c(yAxisScaleFactors[3], yAxisScaleFactors[4])
#check if data is there/yAxisScales are numbers (otherwise plot fails) then do subplot without data (no points are plotted)
if ((is.na(yAxisScale)[1] == TRUE) || (is.na(yAxisScale)[2] == TRUE) || (is.infinite(yAxisScale)[1] == TRUE) || (is.infinite(yAxisScale)[2] == TRUE)) {
yAxisScale <- extendrange(kInYtable[,param], f = yAxisScaleFactors[5])
} else {
yAxisScale <- extendrange(r = yAxisScale, f = yAxisScaleFactors[5])
}
}
#2.4.2 plot data
# iterate over categories
for(factor in factors){
index = which(factors == factor)
if(index == 1){ #is it bulk data?
xAxisTitle <- paste(param," ( ",corrTable$repX[1]," )",sep="")
yAxisTitle <- paste(param," ( ",corrTable$repY[1]," )",sep="")
par(ps = 18)
plot(corrTable$X[which(corrTable$catVarX == factor)],corrTable$Y[which(corrTable$catVarX == factor)], xlim = xAxisScale, ylim = yAxisScale, main = title, xlab = xAxisTitle, ylab = yAxisTitle, cex.lab = 1, cex.axis = 0.9, cex.main = 1.2, cex.sub = 1, col = factorColors[index], pch = factorSymbols[index], cex = scaleFactors[1])
} else {
points(corrTable$X[which(corrTable$catVarX == factor)],corrTable$Y[which(corrTable$catVarX == factor)], col = factorColors[index], pch = factorSymbols[index], bg = factorColors[index], cex = scaleFactors[2])
}
}
# add the legend
legend(legendPosition, pch= factorSymbols[1:length(factors)], factors, col = factorColors, pt.bg = factorColors, cex = legendSize, y.intersp = 1.5, plot = plotLegend)
# adds regression lines
if(useRegression){
regression <- lm(corrTable$Y ~ corrTable$X)
abline(regression)
}
if(usePearson){
correlation <- cor.test(corrTable$X,corrTable$Y, method = "pearson")
corrEstimate <- correlation$"estimate"
mtext(paste("Pearson correlation = ",round(corrEstimate, digits = 3),", n = ",sampleIDmatch), adj = 0, line = 0, cex = pearsonTextFactor)
}
} else { #error empty table
plot(0,0)
mtext("not enough samples for correlation", adj = 0, line = 0.5, cex = 1.5)
}
} else { #error table merge didnt fit (check sample IDs)
plot(0,0)
mtext("sampleID not unique", adj = 0, line = 0.5, cex = 1.5)
}
})
]]>
########################################################################################
# name: Lineplot with plot options
# author: Martin Stoeter, modified from Antje Niederleins' Barplot
# category: basic/lineplots
# preview: LinePlot.png
Flexible template to create a line plot or line plot grid with optional errorbars
HINT: use GroupBy node to aggregated the data to e.g mean and sd columns
Parameter:
Bar height - One or multiple numerical variables. Each value will result in one bar
Error bar checkbox - Draw errorbars?
Error bar - Error bar values corresponding to the height values (same number of columns have to be selected)
To use a flow variable check box and type in variable names using the format: FLOWVAR(variable name)
x-axis - Label to put at the x-axis for each bar (mulitple columns can be selected to combine information)
2D-grid grouping parameter - Allows to split the dataset into multiple plots by this condition (multiple columns can be selected to combine information)
bar colour - Colour bars by condition (mulitple columns can be selected to combine information)
Layout Options:
- select background/theme and set general font size in plot (default = 14)
- plot points or lines or both
- set size and alpha value (transparency) of points, lines and error bars (default = [2,0.5,0.1] and [1,0.5,0.5])
- select different color models for the plot (see: http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/#rcolorbrewer-palette-chart )
- optional the rows and columns can be defined for the 2D grid
- optional the dogde width can adjusted (default = 0.9), set to 0 for no dodge (all points on same x value)
- give plot title and title factor (default = 1.2)
- x-axis test: angle, text size factor for x-/y-axis (default = 0.8)
- y-axis title (or use parameter name: for 2D grid => 'height'), axis title factor (default = 1.0)
- adjust y-axis scale (check fixed and enter min + max; free for 2D grid)
- give legend title, adjust position (fixed position outside diagram or free(range:0-1): [0.1,0.9] = top-left) and legend title/text size factor(default = 0.8)
######
$$$TEMPLATE_DESC$$$
#1.0 Parameter selection
#R debugging: delete all variables except kIn
#rm(list=ls(all=TRUE)[which(ls(all=TRUE) != "kIn")])
# Define your numerical parameters represented by bar height
barHeight = c()
# Define your numerical parameters for error bars
plot.Errorbars =
plot.Errorbars.Plus =
plot.Errorbars.Negative =
barError = c()
#define use of flow variables
#define x-axis, grid and color group
xFactor = c()
facetBy = c()
colourBy = c()
#diagram options
plotPointsLines =
pointLineSize = as.numeric(c())
alphaValue = as.numeric(c())
plotTheme =
plotTextSize = as.numeric(c())
twoDgridRow = c()
twoDgridColumn = c()
positionDodgeWidth = as.numeric(c())
plotTitleSize = as.numeric(c())
xAngle = as.numeric(c())
axisTextSizeFactor = as.numeric(c())
useParameternameAsAxisLabel =
axisTitleSizeFactor = as.numeric(c())
useManualYaxisScale =
yAxisScale = as.numeric(c())
free.scales =
yAxisScaleLog10 =
yAxisTextLog10 =
legendPosition =
useLegendCoordinate =
legendCoordinate = as.numeric(c())
legendTitle =
legendTextSizeFactor = as.numeric(c())
rotateLegend =
40)) pointLineSize[1] <- 2
if (is.na(pointLineSize[2]) | (pointLineSize[2] < 0) | (pointLineSize[2] > 40)) pointLineSize[2] <- 0.5
if (is.na(pointLineSize[3]) | (pointLineSize[3] < 0) | (pointLineSize[3] > 10)) pointLineSize[3] <- 0.1
if (is.na(alphaValue[1]) | (alphaValue[1] < 0) | (alphaValue[1] > 1)) pointLineSize[1] <- 1
if (is.na(alphaValue[2]) | (alphaValue[2] < 0) | (alphaValue[2] > 1)) pointLineSize[2] <- 0.5
if (is.na(alphaValue[3]) | (alphaValue[3] < 0) | (alphaValue[3] > 1)) pointLineSize[3] <- 0.5
if (is.na(plotTitle)) plotTitle <- NULL #default if no title is given
if (is.na(plotTextSize[1]) | (plotTextSize[1] < 0) | (plotTextSize[1] > 40)) plotTextSize[1] <- 14
if (is.na(plotTitleSize[1]) | (plotTitleSize[1] < 0) | (plotTitleSize[1] > 5)) plotTitleSize[1] <- 1.2
if (is.na(yAxisLabel)) yAxisLabel <- NULL
if (is.na(xAngle)) xAngle <- 0
if (is.na(axisTextSizeFactor[1]) | (axisTextSizeFactor[1] < 0) | (axisTextSizeFactor[1] > 5)) axisTextSizeFactor[1] <- 0.8
if (is.na(axisTextSizeFactor[2]) | (axisTextSizeFactor[2] < 0) | (axisTextSizeFactor[2] > 5)) axisTextSizeFactor[2] <- 0.8
if (is.na(axisTitleSizeFactor[1]) | (axisTitleSizeFactor[1] < 0) | (axisTitleSizeFactor[1] > 5)) axisTitleSizeFactor[1] <- 1
if (is.na(axisTitleSizeFactor[2]) | (axisTitleSizeFactor[2] < 0) | (axisTitleSizeFactor[2] > 5)) axisTitleSizeFactor[2] <- 1
if (is.na(yAxisScale[1]) | is.na(yAxisScale[2])) yAxisScale <- NULL
if (useParameternameAsAxisLabel) yAxisLabel <- barHeight
if (is.na(legendCoordinate[1]) | is.na(legendCoordinate[2]) | (legendCoordinate[1] < 0) | (legendCoordinate[1] > 1) | (legendCoordinate[2] < 0) | (legendCoordinate[2] > 1)) useLegendCoordinate <- FALSE
if (is.na(legendTextSizeFactor[1]) | (legendTextSizeFactor[1] < 0) | (legendTextSizeFactor[1] > 5)) legendTextSizeFactor[1] <- 0.8
if (is.na(legendTextSizeFactor[2]) | (legendTextSizeFactor[2] < 0) | (legendTextSizeFactor[2] > 5)) legendTextSizeFactor[2] <- 0.8
if (xAngle == 0 ) xAxisAjust <- c(0.5,1.0) #xAxisAjust = c(hjust,vjust)
if (xAngle == 45) xAxisAjust <- c(1.0,1.0)
if (xAngle == 90) xAxisAjust <- c(1.0,0.5)
#2.3 calculate
# create rowID column if needed
if("-ROW ID-" %in% xFactorCol) kIn[,"-ROW ID-"] <- rownames(kIn)
# combine columns if necessary
if(length(xFactor) > 1) {
xFactorCol <- paste(xFactor, collapse = " + ")
kIn[,xFactorCol] <- apply(kIn[,xFactor], 1, paste, collapse = " + ")
}
if(length(facetBy) > 1) {
facetCol <- paste(facetBy, collapse = " + ")
kIn[,facetCol] <- apply(kIn[,facetBy], 1, paste, collapse = " + ")
}
if(length(colourBy) > 1) {
colourCol <- paste(colourBy, collapse = " + ")
kIn[,colourCol] <- apply(kIn[,colourBy], 1, paste, collapse = " + ")
}
# extract necessary data and reshape it
meanData <- kIn[,c(barHeight,xFactorCol, facetCol, colourCol)]
meanDataLong <- melt(meanData, measure.vars = barHeight, variable_name = "- PARAMETERS -")
names(meanDataLong)[which(names(meanDataLong) == "value")] <- "height"
#check if values/data is there, to prevent R error message
if(length(which(!is.na(meanDataLong$height))) == 0){
meanDataLong$height[1] <- 0
plotErrorMessage <- TRUE
} else {
plotErrorMessage <-FALSE
}
# add errorbar data
if(plot.Errorbars) {
sdData <- kIn[,c(barError,xFactorCol, facetCol, colourCol)]
sdDataLong <- melt(sdData, measure.vars = barError)
meanDataLong$error <- sdDataLong$value
if(plot.Errorbars.Negative) {
meanDataLong$low <- with(meanDataLong, height - error)
} else {
meanDataLong$low <- with(meanDataLong, height)
}
if(plot.Errorbars.Plus) {
meanDataLong$high <- with(meanDataLong, height + error)
} else {
meanDataLong$high <- with(meanDataLong, height)
}
if(yAxisScaleLog10) {
meanDataLong[which(meanDataLong$low < 0),"low"] <- 0.000000001
}
}
if(xFactorFlag) xFactorCol <- "- PARAMETERS -"
if(facetFlag) facetCol <- "- PARAMETERS -"
if(colourFlag) colourCol <- "- PARAMETERS -"
if(is.na(legendTitle)) legendTitle <- colourCol #default if no title is given
if(!is.null(facetBy)) {
facetTitle <- facetCol
meanDataLong$template.facet.column <- meanDataLong[,facetCol]
facetCol <- "template.facet.column"
}
if (is.null(colourCol)) { #set grouping column for line plot
groupData <- "- PARAMETERS -"
} else {
groupData <- colourCol
}
if(!is.null(colourBy)) meanDataLong[,colourCol] <- factor(meanDataLong[,colourCol])
#convert to discrete format
meanDataLong[,xFactorCol] <- factor(meanDataLong[,xFactorCol])
meanDataLong[,"ggplot_groupid"] <- 1 : nrow(meanDataLong) # variable colorCol needs to be replaced with ggplot_groupid
#2.4.1 plot
p <- ggplot(meanDataLong, aes(x = get(xFactorCol), y = height, group = ggplot_groupid))
my.dodge <- position_dodge(width = positionDodgeWidth)
if(!is.null(colourBy)) {
if(plotPointsLines == "points_and_lines" || plotPointsLines == "points_only") {
p <- p + geom_point(aes(colour = factor(get(colourCol))), position = my.dodge, size = pointLineSize[1], alpha = alphaValue[1])}
if(plotPointsLines == "points_and_lines" || plotPointsLines == "lines_only") {
p <- p + geom_line(aes(colour = factor(get(colourCol)), group = get(groupData)), position = my.dodge, size = pointLineSize[2], alpha = alphaValue[2])}
if(plot.Errorbars) {
p <- p + geom_errorbar(aes(colour = factor(get(colourCol)), ymin = low, ymax = high, group = get(colourCol)), position = my.dodge, width = pointLineSize[3], alpha = alphaValue[3])}
} else {
if(plotPointsLines == "points_and_lines" || plotPointsLines == "points_only") {
p <- p + geom_point(colour = "black", position = my.dodge, size = pointLineSize[1], alpha = alphaValue[1])}
if(plotPointsLines == "points_and_lines" || plotPointsLines == "lines_only") {
p <- p + geom_line(aes(group = get(groupData)), colour = "black", position = my.dodge, size = pointLineSize[2], alpha = alphaValue[2])}
if(plot.Errorbars) {
p <- p + geom_errorbar(aes(ymin = low, ymax = high), colour = "black", position = my.dodge, width = pointLineSize[3], alpha = alphaValue[3])}
}
if(!is.null(facetBy)) {
p <- p + facet_wrap(~ template.facet.column, nrow = twoDgridRow, ncol = twoDgridColumn, scales=free.scales)
fTitle <- paste("Grid factor: ",facetTitle,sep = "")
if(!is.null(plotTitle)) plotTitle <- paste(plotTitle,fTitle,sep = " / ") else plotTitle <- fTitle
p <- p + ggtitle(plotTitle)
} else {
if(!is.null(plotTitle)) p <- p + ggtitle(plotTitle)
}
#2.4.1 layout plot
#general
if(plotTheme == "grey") p <- p + theme_grey(base_size=plotTextSize[1])
if(plotTheme == "black-white") p <- p + theme_bw(base_size=plotTextSize[1])
if(plotTheme == "linedraw") p <- p + theme_linedraw(base_size=plotTextSize[1])
if(plotTheme == "light") p <- p + theme_light(base_size=plotTextSize[1])
if(plotTheme == "classic") p <- p + theme_classic(base_size=plotTextSize[1])
#2.4.2 set general layout of plot
#title options
p <- p + theme(plot.title = element_text(size = plotTextSize[1] * plotTitleSize[1]))
#axis label options
p <- p + labs(x = xFactorCol, y = yAxisLabel)
p <- p + theme(axis.title.x = element_text(size = plotTextSize[1] * axisTitleSizeFactor[1]), axis.title.y = element_text(size = plotTextSize[1] * axisTitleSizeFactor[2]))
p <- p + theme(axis.text.x = element_text(angle = xAngle, hjust = xAxisAjust[1], vjust = xAxisAjust[2], size = plotTextSize[1] * axisTextSizeFactor[1]), axis.text.y = element_text(size = plotTextSize[1] * axisTextSizeFactor[2]))
# fixing the y-axis labeling, make parameter name or custom y-axis label instead of "height", only if no multi-parameteric plot and only if no y-Axis label was added in the GUI
if(((!is.null(facetBy) && "-USE COLUMN SELECTION-" %in% facetBy )|| length(barHeight) > 1) && is.null(yAxisLabel)) yAxisLabel <- "height"
if(useManualYaxisScale) p <- p + coord_cartesian(ylim = yAxisScale)
if(yAxisScaleLog10) {
p <- p + scale_y_log10(name = yAxisLabel) # do y-axis in log 10 scale
if(yAxisTextLog10) p <- p + scale_y_log10(name = yAxisLabel, breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x)))
} else {
p <- p + scale_y_continuous(name = yAxisLabel) # do normal y-axis
if(yAxisTextLog10) p <- p + scale_y_continuous(name = yAxisLabel, breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x)))
}
# color model checks: is it available? is it defined for the grouping column?
if(useKNIMEColors && !exists("kIn.color.model")) {
stop("No KNIME color model provided. Script was stopped!")
useKNIMEColors <- FALSE
}
if(useKNIMEColors && names(kIn.color.model[1]) != colourCol) {
stop(paste("KNIME color model is different (", names(kIn.color.model[1]), ") from selected color grouping column (", colourCol, ") in template. Script was stopped!"))
useKNIMEColors <- FALSE
}
if(useKNIMEColors) {
kIn.color.model <- kIn.color.model[order(kIn.color.model[,colourCol]),]
kIn.color.model$color <- as.character(kIn.color.model$color)
colourCol <- names(kIn.color.model)[1]
factorColors <- kIn.color.model[,2]
names(factorColors) <- kIn.color.model[,1]
}
# color settings
if(useKNIMEColors) {
p <- p + scale_color_manual(name = colourCol, values = factorColors)
p <- p + scale_fill_manual(name = colourCol, values = factorColors)
} else {
if(colorPalette == "ggplot default") {
p <- p + scale_color_discrete(name = colourCol)
p <- p + scale_fill_discrete(name = colourCol)
} else {
p <- p + scale_color_brewer(name = colourCol, palette = colorPalette)
p <- p + scale_fill_brewer(name = colourCol, palette = colorPalette)
}
}
#legend: legend title, text style and rotation
p <- p + guides(color = guide_legend(title = legendTitle), fill = guide_legend(title = legendTitle)) + theme(legend.title = element_text(size = plotTextSize[1] * legendTextSizeFactor[1], face = "bold"), legend.text = element_text(size = plotTextSize[1] * legendTextSizeFactor[2]))
if(rotateLegend) p <- p + guides(fill = guide_legend(title = legendTitle, direction = "horizontal", title.position = "top", label.position = "bottom", label.hjust = 0.5, label.vjust = 0.5, label.theme = element_text(angle = 90)))
if (useLegendCoordinate) {
p <- p + theme(legend.position = legendCoordinate, legend.background = element_rect(fill = "transparent",colour = NA))
} else {
p <- p + theme(legend.position = legendPosition)
}
if(plotErrorMessage) p <- p + ggtitle("ERROR: NO DATA!!!")
print(p)
]]>
########################################################################################
# name: Heatmap / Plate Heatmap Plotter
# author: Martin Stoeter
# category: screening/heatmap
# preview: Heatmap.png
Plots heatmaps e.g. as 2D matrix with color code as variable.
Can be used to plot plate heatmap if plateRow and plateColumn is chosen as 2D matrix.
Parameter:
Define x-/y-axis columns to set up the 2D matrix of the heatmap
- spaces between axis ticks / labels can ge specified, -Auto- calculates that automatically, invert sets the direction of the column
Define variable column that is plotted as as color in heatmap
- to use a flow variable check box and type in variable names using the format: FLOWVAR(variable name)
- define color for minimum, middle and maximum value to use continuous color space
- or select different color models for the plot (see: http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/#rcolorbrewer-palette-chart )
- if 'default min-max' is selected calculation method for middle color can be chosen or custom value set
Layout Options:
- select background/theme and set general font size in plot (default = 14) (see: http://www.sthda.com/english/wiki/ggplot2-themes-and-background-colors-the-3-elements)
- theme 'nothing' just plots the heatmap without any labels
- set size and alpha value (transparency) of points, lines and error bars (default = [2,0.5,0.1] and [1,0.5,0.5])
- give plot title and title factor (default = 1.2)
- x-axis text: angle, text size factor for x-/y-axis (default = 0.8)
- give legend title, adjust position (fixed position outside diagram or free(range:0-1): [0.1,0.9] = top-left) and legend title/text size factor(default = 0.8)
HINT: usage as Plate Heatmap Plotter:
- use plateRow as y-axis and check invert
- use plateColunm as x-axis
- set range of tick labels from -AUTO- to 1
- use variables for color or use flowvariable option to plot many heatmaps
######
$$$TEMPLATE_DESC$$$
#1.0 Parameter selection
#R debugging: delete all variables except kIn
#rm(list=ls(all=TRUE)[which(ls(all=TRUE) != "kIn")])
# define 2D matrix as grid for heatmap
xValue =
yValue =
numberxAxisTickLabels = c()
numberyAxisTickLabels = c()
invertxAxisDirection =
invertyAxisDirection =
# Define variable to be plotted as color
parameter =
#define use of flow variables
calulationMidValue =
#diagram options
plotTheme =
plotTextSize = as.numeric(c())
plotTitleSize = as.numeric(c())
xAngle = as.numeric(c())
axisTextSizeFactor = as.numeric(c())
axisTitleSizeFactor = as.numeric(c())
legendPosition =
useLegendCoordinate =
legendCoordinate = as.numeric(c())
legendTitle =
legendTextSizeFactor = as.numeric(c())
rotateLegend =
1) stop("KNIME color model does not fit to selected factor column")
subdata[1,]
})
# create color vector
names(colorTable) <- factors
colorTable <- do.call("rbind", colorTable)
factorColors <- rgb(colorTable$R, colorTable$G, colorTable$B, colorTable$A, max = 255)
names(factorColors) <- factors
}
}
#2.2.2 manage RGG to R: set scales to default and check scales
if (is.na(plotTitle)) plotTitle <- NULL #default if no title is given
if (is.na(plotTextSize[1]) | (plotTextSize[1] < 0) | (plotTextSize[1] > 40)) plotTextSize[1] <- 14
if (is.na(plotTitleSize[1]) | (plotTitleSize[1] < 0) | (plotTitleSize[1] > 5)) plotTitleSize[1] <- 1.2
if (is.na(as.numeric(numberxAxisTickLabels))) {
numberxAxisTickLabels <- 0 #e.g. is equal to "-AUTO-"
} else {
numberxAxisTickLabels <- as.numeric(numberxAxisTickLabels)
}
if (is.na(as.numeric(numberyAxisTickLabels))) {
numberyAxisTickLabels <- 0 #e.g. is equal to "-AUTO-"
} else {
numberyAxisTickLabels <- as.numeric(numberyAxisTickLabels)
}
if (is.na(axisTextSizeFactor[1]) | (axisTextSizeFactor[1] < 0) | (axisTextSizeFactor[1] > 5)) axisTextSizeFactor[1] <- 0.8
if (is.na(axisTextSizeFactor[2]) | (axisTextSizeFactor[2] < 0) | (axisTextSizeFactor[2] > 5)) axisTextSizeFactor[2] <- 0.8
if (is.na(axisTitleSizeFactor[1]) | (axisTitleSizeFactor[1] < 0) | (axisTitleSizeFactor[1] > 5)) axisTitleSizeFactor[1] <- 1
if (is.na(axisTitleSizeFactor[2]) | (axisTitleSizeFactor[2] < 0) | (axisTitleSizeFactor[2] > 5)) axisTitleSizeFactor[2] <- 1
if (is.na(legendCoordinate[1]) | is.na(legendCoordinate[2]) | (legendCoordinate[1] < 0) | (legendCoordinate[1] > 1) | (legendCoordinate[2] < 0) | (legendCoordinate[2] > 1)) useLegendCoordinate <- FALSE
if (is.na(legendTextSizeFactor[1]) | (legendTextSizeFactor[1] < 0) | (legendTextSizeFactor[1] > 5)) legendTextSizeFactor[1] <- 0.8
if (is.na(legendTextSizeFactor[2]) | (legendTextSizeFactor[2] < 0) | (legendTextSizeFactor[2] > 5)) legendTextSizeFactor[2] <- 0.8
if (xAngle == 0 ) xAxisAjust <- c(0.5,1.0) #xAxisAjust = c(hjust,vjust)
if (xAngle == 45) xAxisAjust <- c(1.0,1.0)
if (xAngle == 90) xAxisAjust <- c(1.0,0.5)
#2.3 calculate
# create rowID column if needed
parameterCols <- c(xValue ,yValue , parameter)
x <- kIn[,xValue]
y <- kIn[,yValue]
z <- kIn[,parameter]
#make axis label ticks / breaks for labelling the axes
xLevels <- nlevels(factor(x))
yLevels <- nlevels(factor(y))
if (numberxAxisTickLabels == 0) {
xBreacks <- seq(min(x), max(x), length.out = xLevels)
} else {
xBreacks <- seq(min(x), max(x), by = numberxAxisTickLabels)
}
if (numberyAxisTickLabels == 0) {
yBreacks <- seq(min(y), max(y), length.out = yLevels)
} else {
yBreacks <- seq(min(y), max(y), by = numberyAxisTickLabels)
}
if (invertxAxisDirection) xBreacks <- rev(xBreacks)
if (invertyAxisDirection) yBreacks <- rev(yBreacks)
plotData <- data.frame(x,y,z)
# define the color value ranges for color palette from ColorBrewer
if (colorPalette != "default min-max") {
plotData$col <- cut(plotData$z,breaks = seq(from = min(plotData$z), to = max(plotData$z)+0.000000001, length.out = maxNumberColors), right = FALSE)
} else {
if (calulationMidValue == "min+max/2") midValue <- (min(plotData$z, na.rm = TRUE) + max(plotData$z, na.rm = TRUE)) / 2
if (calulationMidValue == "mean") midValue <- mean(plotData$z, na.rm = TRUE)
if (calulationMidValue == "median") midValue <- median(plotData$z, na.rm = TRUE)
if (calulationMidValue == "custom") midValue <- midValue
}
#2.4.1 plot
#ggplot(plotData, aes(x=x, y=y)) + geom_tile(aes(fill=z)) + scale_fill_gradient(low="black", high="white")
p <- ggplot(plotData, aes(x=x, y=y))
if (colorPalette == "default min-max") {
p <- p + geom_raster(aes(fill=z)) + scale_fill_gradient2(low = minColor, mid = midColor, high = maxColor, midpoint = midValue, name = legendTitle)
} else {
p <- p + geom_raster(aes(fill=col)) + scale_fill_brewer(palette = colorPalette)
}
#2.4.1 layout plot
#general
if(plotTheme == "grey") p <- p + theme_grey(base_size=plotTextSize[1])
if(plotTheme == "black-white") p <- p + theme_bw(base_size=plotTextSize[1])
if(plotTheme == "linedraw") p <- p + theme_linedraw(base_size=plotTextSize[1])
if(plotTheme == "light") p <- p + theme_light(base_size=plotTextSize[1])
if(plotTheme == "minimal") p <- p + theme_minimal(base_size=plotTextSize[1])
if(plotTheme == "classic") p <- p + theme_classic(base_size=plotTextSize[1])
#title options
p <- p + theme(plot.title = element_text(size = plotTextSize[1] * plotTitleSize[1]))
if(is.null(plotTitle)) {
p <- p + ggtitle(parameter)
} else {
p <- p + ggtitle(plotTitle)
}
#axis label options
if (invertxAxisDirection) {
p <- p + scale_x_reverse(xValue, breaks=xBreacks)
} else {
p <- p + scale_x_continuous(xValue, breaks=xBreacks)
}
if (invertyAxisDirection) {
p <- p + scale_y_reverse(yValue, breaks=yBreacks)
} else {
p <- p + scale_y_continuous(yValue, breaks=yBreacks)
}
p <- p + theme(axis.title.x = element_text(size = plotTextSize[1] * axisTitleSizeFactor[1]), axis.title.y = element_text(size = plotTextSize[1] * axisTitleSizeFactor[2]))
p <- p + theme(axis.text.x = element_text(angle = xAngle, hjust = xAxisAjust[1], vjust = xAxisAjust[2], size = plotTextSize[1] * axisTextSizeFactor[1]), axis.text.y = element_text(size = plotTextSize[1] * axisTextSizeFactor[2]))
#legend
if(rotateLegend) {
p <- p + scale_color_discrete(name = legendTitle, guide = guide_legend(direction = "horizontal", title.position = "top", label.position="bottom", label.hjust = 0.5, label.vjust = 0.5, label.theme = element_text(angle = 90)))
} else {
p <- p + scale_color_discrete(name = legendTitle)
}
p <- p + theme(legend.title = element_text(size = plotTextSize[1] * legendTextSizeFactor[1], face = "bold"), legend.text = element_text(size = plotTextSize[1] * legendTextSizeFactor[2]))
if (useLegendCoordinate) {
p <- p + theme(legend.position = legendCoordinate, legend.background = element_rect(fill = "transparent",colour = NA))
} else {
p <- p + theme(legend.position = legendPosition)
}
if(plotTheme == "nothing") {
p <- p + theme_classic()
p <- p + theme(line = element_blank(), text = element_blank(), line = element_blank(), title = element_blank(), legend.position = "none")
}
print(p)
]]>
########################################################################################
# name: 5D-Scatterplot
# author: Antje Janosch
# category: scatterplots
# preview: scatterplot.png
A simple scatterplot which is able to use KNIME-color , -shape and -size model (requires minimum version 3.0.0. for R-scripting integration)
######
a description
#1.0 Parameter selection
# b) X-Axis
x.col = c()
#define use of flow variables
# c) Y-Axis
y.col = c()
#define use of flow variables
# d) color, size, shape model
# e) #diagram options
plotTheme =
plot.text.size = as.numeric(c())
point.fixed.size = as.numeric(c())
point.alpha = as.numeric(c())
40)) plot.text.size[1] <- 14
#if (is.na(plotTitleSize[1]) | (plotTitleSize[1] < 0) | (plotTitleSize[1] > 5)) plotTitleSize[1] <- 1.2
# setting x-axis angle
x_angle <- as.numeric(x_angle)
if (is.na(x_angle)) x_angle <- 0
if (x_angle == 0 ) {
x_axis_ajust <- c(0.5,1.0) # x_axis_ajust = c(hjust,vjust)
} else {
if (x_angle == 45) {
x_axis_ajust <- c(1.0,1.0)
} else {
if (x_angle == 90) {
x_axis_ajust <- c(1.0,0.5)
} else {
x_axis_ajust <- c(0.5,1.0)
}
}
}
if(size.model) {
if (!is.na(point.fixed.size)) warning("Given fixed point size will be ignored because size model is used.")
point.fixed.size <- NULL
} else {
if (is.na(point.fixed.size) | point.fixed.size < 0) point.fixed.size <- 2
}
if (is.na(point.alpha) | point.alpha < 0 | point.alpha > 1) point.fixed.size <- 0.7
# check models
if(size.model && !exists("kIn.size.model"))
warning("No KNIME size model provided.")
if(color.model && !exists("kIn.color.model"))
warning("No KNIME color model provided.")
if(shape.model && !exists("kIn.shape.model"))
warning("No KNIME shape model provided.")
keep <- c(x = x.col,y = y.col)
if(size.model & exists("kIn.size.model")) {
keep <- c(keep, size = kIn.size.model)
} else size.model <- FALSE
if(color.model & exists("kIn.color.model")) {
keep <- c(keep, color = names(kIn.color.model)[1])
} else color.model <- FALSE
if(shape.model & exists("kIn.shape.model")) {
keep <- c(keep, shapeVal = names(kIn.shape.model)[1])
}else shape.model <- FALSE
#2.3 calculate
data <- kIn[,match(keep, names(kIn))]
names(data) <- names(keep)
if(size.model) {
my.trans <- trans_new("KNIME size model", "kIn.size.model.fun", function(x) x)
}
color.model.discrete <- FALSE
if(color.model) {
kIn.color.model$color <- as.character(kIn.color.model$color)
if(!is.numeric(kIn.color.model[,1])) color.model.discrete <- TRUE
}
if(shape.model) {
data <- merge(data, kIn.shape.model, by.x = "shapeVal", by.y = names(kIn.shape.model)[1])
data$pch <- factor(data$pch)
shapeValues <- kIn.shape.model$pch[match(levels(data$shapeVal),kIn.shape.model[,1])]
}
#2.4.1 plot
p <- ggplot(data, aes(x = x, y = y)) + geom_point(alpha = point.alpha, size = point.fixed.size)
#geom_point(aes(size = size, color = color, shape = shapeVal))
#2.4.2 set general layout of plot
if(plotTheme == "grey") p <- p + theme_grey(base_size=plot.text.size[1])
if(plotTheme == "black-white") p <- p + theme_bw(base_size=plot.text.size[1])
if(plotTheme == "linedraw") p <- p + theme_linedraw(base_size=plot.text.size[1])
if(plotTheme == "light") p <- p + theme_light(base_size=plot.text.size[1])
if(plotTheme == "minimal") p <- p + theme_minimal(base_size=plot.text.size[1])
if(plotTheme == "classic") p <- p + theme_classic(base_size=plot.text.size[1])
if(plotTheme == "nothing") p <- p + theme_classic() + theme(line = element_blank(), text = element_blank(), title = element_blank(), legend.position = "none")
#2.4.3 use models in plot
if(size.model) {
p <- p + aes(size = size)
p <- p + scale_size_identity(kIn.size.model, trans = my.trans, guide = "legend")
}
if(color.model) {
p <- p + aes(color = color)
if(color.model.discrete) {
col.vec <- kIn.color.model[,2]
names(col.vec) <- kIn.color.model[,1]
p <- p + scale_color_manual(names(kIn.color.model)[1], values = col.vec)
} else {
p <- p + scale_color_gradient(names(kIn.color.model)[1], low = kIn.color.model$color[1], high = kIn.color.model$color[2])
}
}
if(shape.model) {
p <- p + aes(shape = shapeVal)
p <- p + scale_shape_manual(names(kIn.shape.model)[1], values = shapeValues)
}
#2.4.4 set specific layout options
p <- p + theme(axis.text.x = element_text(angle = x_angle, hjust = x_axis_ajust[1], vjust = x_axis_ajust[2]))
p <- p + labs(title = plot.title, x = x.col, y = y.col)
print(p)
]]>
########################################################################################
# name: Multiparametric Boxplot Grid (ggplot)
# author: Antje Janosch
# category: basic/boxplots
# preview: boxplot_ggplot.png
A grid of parallel boxplots, one for each selected assay parameter. The number of actual parallel boxplots is defined by a categorical variable (like a well-treatment)
######
$$$TEMPLATE_DESC$$$
# 1. Parameter selection
# a) Define your categorical variable of interest
# make sure that the sorting of the data is being preserved
# b) Define the grouping factor
# b) Define your assay parameters of interest
params = c()
free.scales =
#diagram options
plotTheme =
plotTextSize = as.numeric(c())
# 2. r-code
########################################################################################
# name: Barplot or Boxplot with points
# author: Martin Stoeter
# category: basic/bar-boxplots
# preview: bar-boxplot.png
Flexible template to create a barplot or a boxplot with points (optional add violins or error bars)
Parameter:
Parameter to plot - Select a column with values to plot
To use a flow variable check box and type in variable name using the format: FLOWVAR(variable name)
Plot style - Select to plot the data as barplot, boxplot or none of those (e.g. just plot points or violins)
Select checkboxs to plot points, violins and/or errorbars?
x-axis - Label to put at the x-axis
2D-grid grouping - Allows to split the dataset into multiple plots by this condition
colourby - Colour bars by condition
Change point size or jitterin width if neccessary
HINT: points are plotted twice with second being a little smaller (1. is line, 2. is fill; play with alpha values...)
Trim distribution of violins, or change alpha value of violins
If robust statistics is checked then median and mad will be used for bar height and error bar; use dogde to change gap of data in x
Layout Options:
- select background/theme and set general font size in plot (default = 14)
- select different color models for the plot (see: http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/#rcolorbrewer-palette-chart )
- give plot title and title factor (default = 1.2)
- x-axis test: angle, text size factor for x-/y-axis (default = 0.8)
- y-axis title (or use parameter name: for 2D grid => 'height'), axis title factor (default = 1.0)
- adjust y-axis scale (check fixed and enter min + max)
- give legend title, adjust position (fixed position outside diagram or free(range:0-1): [0.1,0.9] = top-left) and legend title/text size factor(default = 0.8)
######
$$$TEMPLATE_DESC$$$
#1.0 Parameter selection
# Define your numerical parameters to be plotted
#define use of flow variables
yParameters = c()
# Define your numerical parameters for error bars
plotType = c()
plotPoints =
plotErrorbars =
plotViolins =
#define x-axis, grid and color group
xFactor = c()
facetBy = c()
colourBy = c()
#diagram options
pointSize = as.numeric(c())
alphaValue = as.numeric(c())
jitterWidth = as.numeric(c())
trimViolin =
alphaViolin = as.numeric(c())
robustStatistics =
dodgeWidth = as.numeric(c())
#diagram options
plotTheme =
plotTextSize = as.numeric(c())
twoDgridRow = c()
twoDgridColumn = c()
plotTitleSize = as.numeric(c())
xAngle = as.numeric(c())
axisTextSizeFactor = as.numeric(c())
useParameternameAsAxisLabel =
axisTitleSizeFactor = as.numeric(c())
useManualYaxisScale =
yAxisScale = as.numeric(c())
free.yscales =
legendPosition =
useLegendCoordinate =
legendCoordinate = as.numeric(c())
legendTitle =
legendTextSizeFactor = as.numeric(c())
rotateLegend =
40)) plotTextSize[1] <- 14
if (is.na(plotTitleSize[1]) | (plotTitleSize[1] < 0) | (plotTitleSize[1] > 5)) plotTitleSize[1] <- 1.2
if (is.na(yAxisLabel)) yAxisLabel <- NULL
if (is.na(xAngle)) xAngle <- 0
if (is.na(axisTextSizeFactor[1]) | (axisTextSizeFactor[1] < 0) | (axisTextSizeFactor[1] > 5)) axisTextSizeFactor[1] <- 0.8
if (is.na(axisTextSizeFactor[2]) | (axisTextSizeFactor[2] < 0) | (axisTextSizeFactor[2] > 5)) axisTextSizeFactor[2] <- 0.8
if (is.na(axisTitleSizeFactor[1]) | (axisTitleSizeFactor[1] < 0) | (axisTitleSizeFactor[1] > 5)) axisTitleSizeFactor[1] <- 1
if (is.na(axisTitleSizeFactor[2]) | (axisTitleSizeFactor[2] < 0) | (axisTitleSizeFactor[2] > 5)) axisTitleSizeFactor[2] <- 1
if (is.na(yAxisScale[1]) | is.na(yAxisScale[2])) yAxisScale <- NULL
if (useParameternameAsAxisLabel) yAxisLabel <- yParametersOriginal
if (is.na(legendCoordinate[1]) | is.na(legendCoordinate[2]) | (legendCoordinate[1] < 0) | (legendCoordinate[1] > 1) | (legendCoordinate[2] < 0) | (legendCoordinate[2] > 1)) useLegendCoordinate <- FALSE
if (is.na(legendTextSizeFactor[1]) | (legendTextSizeFactor[1] < 0) | (legendTextSizeFactor[1] > 5)) legendTextSizeFactor[1] <- 0.8
if (is.na(legendTextSizeFactor[2]) | (legendTextSizeFactor[2] < 0) | (legendTextSizeFactor[2] > 5)) legendTextSizeFactor[2] <- 0.8
if (xAngle == 0 ) xAxisAjust <- c(0.5,1.0) #xAxisAjust = c(hjust,vjust)
if (xAngle == 45) xAxisAjust <- c(1.0,1.0)
if (xAngle == 90) xAxisAjust <- c(1.0,0.5)
if (is.na(jitterWidth)) jitterWidth <- NULL
if (is.na(legendTitle)) legendTitle <- colourByOriginal #default if no title is given
#2.3 calculate
# statistice table kIn.summary
if(robustStatistics) {
kIn.summary <- kIn %>%
group_by_at(vars(c(xFactor, colourBy, facetBy))) %>% # _ at the end means it accepts strings and variables rather then interpretation of code as column name of data frame / table; at means it will evaluated with vars the list of grouping variables, e.g. here facetBy might be NULL and will not lead to crash of code
summarise(
median = median(.data[[yParameters]], na.rm = TRUE), # .data[[]] interprets variable as name of column in data frame
mad = mad(.data[[yParameters]], na.rm = TRUE)
) %>%
mutate(errorLow = median - mad) %>%
mutate(errorHigh = median + mad) %>%
rename(!!yParameters := median) # !! means unqouting and yParameters is not interpreted as column name of data frame, instead content of this variable in interpreted as column name; := is neccessary to new value to old (old := new)
} else {
kIn.summary <- kIn %>%
group_by_at(vars(c(xFactor, colourBy, facetBy))) %>%
summarise(
mean = mean(.data[[yParameters]], na.rm = TRUE),
sd = sd(.data[[yParameters]], na.rm = TRUE)
) %>%
mutate(errorLow = mean - sd) %>%
mutate(errorHigh = mean + sd) %>%
rename(!!yParameters := mean)
}
#kIn.summary
#2.4.1 plot
p <- ggplot(kIn, aes_string(x = xFactor, y = yParameters), color = black)
#2.4.1 layout of plot
#general layout
if(plotTheme == "grey") p <- p + theme_grey(base_size=plotTextSize[1])
if(plotTheme == "black-white") p <- p + theme_bw(base_size=plotTextSize[1])
if(plotTheme == "linedraw") p <- p + theme_linedraw(base_size=plotTextSize[1])
if(plotTheme == "light") p <- p + theme_light(base_size=plotTextSize[1])
if(plotTheme == "classic") p <- p + theme_classic(base_size=plotTextSize[1])
if(plotType == "boxplot") p <- p + geom_boxplot(aes_string(fill = colourBy), position = position_dodge(dodgeWidth), outlier.colour = boxPlotOutlierColor)
if(plotType == "barplot") p <- p + geom_bar(aes_string(fill = colourBy), data = kIn.summary, stat = "identity", color = "black", position = position_dodge(dodgeWidth)) #+ geom_jitter(position = position_jitter(0.2))
if(plotPoints) {
if (pointSize[2] < 0.5) {
p <- p + geom_point(aes_string(color = colourBy), shape = 16, alpha = alphaValue[1], size = pointSize[1], position = position_jitterdodge(jitter.width = jitterWidth, dodge.width=dodgeWidth, seed = 1))
#p <- p + geom_point(aes(colour = factor(get(colourCol))), position = my.dodge, size = pointSize[1], alpha = alphaValue[1])
} else {
p <- p + geom_point(aes_string(fill = colourBy), shape = 21, colour = "black", stroke = 1, alpha = alphaValue[1], size = pointSize[1], position = position_jitterdodge(jitter.width = jitterWidth, dodge.width=dodgeWidth, seed = 1))
#p <- p + geom_point(aes(fill = factor(get(colourCol))), shape = 21, colour = "black", stroke = pointLineSize[4], position = my.dodge, size = pointLineSize[1], alpha = alphaValue[1])
}
}
#p <- p + geom_jitter(aes_string(color = colourBy), position = position_dodge(0.9), size = 3)
#doDotPlot <- TRUE
#dotPlotColor <- "darkgrey"
#dotPlotSize <- 0.7
#dotPlotStackRatio <- 0.7
#if(doDotPlot) p <- p + geom_dotplot(binaxis = "y", stackdir = "center", dotsize = dotPlotSize, stackratio = dotPlotStackRatio, fill = dotPlotColor)
#if(doDotPlot) p <- p + geom_jitter(aes_string(x = xFactor, shape = colourBy, color = colourBy), position = position_jitter(0.2), size = 3, dodge.width = 0.8)
if(plotViolins) p <- p + geom_violin(aes_string(color = colourBy), alpha = alphaViolin, trim = trimViolin, inherit.aes = TRUE)
if(plotErrorbars) p <- p + geom_errorbar(aes_string(ymin = "errorLow", ymax = "errorHigh", group = colourBy), data = kIn.summary, width = 0.2, position = position_dodge(dodgeWidth))
#2.4.2 set optional layout of plot
# facet
if(!is.null(facetBy)) p <- p + facet_wrap(as.formula(paste("~", facetBy)), nrow = twoDgridRow, ncol = twoDgridColumn, scales=free.scales)
#title options
p <- p + theme(plot.title = element_text(size = plotTextSize[1] * plotTitleSize[1]))
p <- p + ggtitle(plotTitle)
#axis label options
p <- p + scale_x_discrete(name = xFactorOriginal)
p <- p + theme(axis.title.x = element_text(size = plotTextSize[1] * axisTitleSizeFactor[1]), axis.title.y = element_text(size = plotTextSize[1] * axisTitleSizeFactor[2]))
p <- p + theme(axis.text.x = element_text(angle = xAngle, hjust = xAxisAjust[1], vjust = xAxisAjust[2], size = plotTextSize[1] * axisTextSizeFactor[1]), axis.text.y = element_text(size = plotTextSize[1] * axisTextSizeFactor[2]))
p <- p + scale_y_continuous(name = yAxisLabel) # do normal y-axis
#if(useManualYaxisScale) p <- p + scale_y_continuous(limits = yAxisScale, name = yAxisLabel) #use e.g. limits = c(0,100)
if(useManualYaxisScale) p <- p + coord_cartesian(ylim = yAxisScale) # this does not crop the data like "limits" parameter
# color model checks: is it available? is it defined for the grouping column?
if(useKNIMEColors && !exists("kIn.color.model")) {
stop("No KNIME color model provided. Script was stopped!")
useKNIMEColors <- FALSE
}
if(useKNIMEColors && names(kIn.color.model[1]) != colourByOriginal) {
stop(paste("KNIME color model is different (", names(kIn.color.model[1]), ") from selected color grouping column (", colourByOriginal, ") in template. Script was stopped!"))
useKNIMEColors <- FALSE
}
if(useKNIMEColors) {
kIn.color.model$color <- as.character(kIn.color.model$color)
#colourCol <- names(kIn.color.model)[1]
factorColors <- kIn.color.model[,2]
names(factorColors) <- kIn.color.model[,1]
}
# color settings
if(useKNIMEColors) {
p <- p + scale_color_manual(name = colourBy, values = factorColors)
p <- p + scale_fill_manual(name = colourBy, values = factorColors)
} else {
if(colorPalette == "ggplot default") {
p <- p + scale_color_discrete(name = colourBy)
p <- p + scale_fill_discrete(name = colourBy)
} else {
p <- p + scale_color_brewer(name = colourBy, palette = colorPalette)
p <- p + scale_fill_brewer(name = colourBy, palette = colorPalette)
}
}
#p <- p + scale_fill_manual(values = colorVector) + scale_colour_manual(values = colorVector)
#legend: legend title, text style and rotation
p <- p + guides(color = guide_legend(title = legendTitle), fill = guide_legend(title = legendTitle)) + theme(legend.title = element_text(size = plotTextSize[1] * legendTextSizeFactor[1], face = "bold"), legend.text = element_text(size = plotTextSize[1] * legendTextSizeFactor[2]))
if(rotateLegend) p <- p + guides(color = guide_legend(title = legendTitle), fill = guide_legend(title = legendTitle, direction = "horizontal", title.position = "top", label.position = "bottom", label.hjust = 0.5, label.vjust = 0.5, label.theme = element_text(angle = 90)))
if (useLegendCoordinate) {
p <- p + theme(legend.position = legendCoordinate, legend.background = element_rect(fill = "transparent",colour = NA))
} else {
p <- p + theme(legend.position = legendPosition)
}
#if(plotErrorMessage) p <- p + ggtitle("ERROR: NO DATA!!!")
print(p)
]]>
########################################################################################
# name: Scatterplot with plot options
# author: Martin Stoeter, modified from Antje Niederleins' Barplot
# category: scatterplots
# preview: scatterPlot_options.png
Flexible template to create a scatter plot or scatter plot grid with optional errorbars
In contrary to the LinePlot template, where categorial values are restriced to the x-axis, here numerical values have to be used to have a real scatter plot
HINT: use GroupBy node to aggregated the data to e.g mean and sd columns
Parameter:
x-axis - one numerical variable for x-axis
y-axis - One or multiple numerical variables that will be plotted as y-axis
Error bar checkbox - Draw errorbars?
Error bar - Error bar values corresponding to the y-axis values (same number of columns have to be selected)
To use a flow variable check box and type in variable names using the format: FLOWVAR(variable name)
2D-grid grouping parameter - Allows to split the dataset into multiple plots by this condition (multiple columns can be selected to combine information)
coloured by - Colour of points and lines by condition (mulitple columns can be selected to combine information)
Layout Options:
- select background/theme and set general font size in plot (default = 14)
- plot points or lines or both
- set size and alpha value (transparency) of points, lines and error bars (default = [2,0.5,0.1] and [1,0.5,0.5])
- select different color models for the plot (see: http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/#rcolorbrewer-palette-chart )
- optional the rows and columns can be defined for the 2D grid
- give plot title and title factor (default = 1.2)
- x-axis text: angle, text size factor for x-/y-axis (default = 0.8)
- x-/y-axis title (or use parameter name: for 2D grid => 'height'), axis title factor (default = 1.0)
- adjust x-/y-axis scale (check fixed and enter min + max; free for 2D grid (free scales for x- and/or y-axis independently))
- give legend title, adjust position (fixed position outside diagram or free(range:0-1): [0.1,0.9] = top-left) and legend title/text size factor(default = 0.8)
######
$$$TEMPLATE_DESC$$$
#1.0 Parameter selection
#R debugging: delete all variables except kIn
#rm(list=ls(all=TRUE)[which(ls(all=TRUE) != "kIn")])
#define x-axis
xFactor =
# Define your numerical parameters represented by y-axis
barHeight = c()
# Define your numerical parameters for error bars
plot.Errorbars =
plot.Errorbars.Plus =
plot.Errorbars.Negative =
barError = c()
#define use of flow variables
# grid and color group
facetBy = c()
colourBy = c()
#diagram options
plotPointsLines =
pointLineSize = as.numeric(c())
alphaValue = as.numeric(c())
plotTheme =
plotTextSize = as.numeric(c())
twoDgridRow = c()
twoDgridColumn = c()
plotTitleSize = as.numeric(c())
useParameterXnameAsAxisLabel =
axisTextSizeFactorX = as.numeric(c())
xAngle = as.numeric(c())
useManualXaxisScale =
xAxisScale = as.numeric(c())
free.xscales =
useParameterYnameAsAxisLabel =
axisTextSizeFactorY = as.numeric(c())
useManualYaxisScale =
yAxisScale = as.numeric(c())
free.yscales =
yAxisScaleLog10 =
yAxisTextLog10 =
legendPosition =
useLegendCoordinate =
legendCoordinate = as.numeric(c())
legendTitle =
legendTextSizeFactor = as.numeric(c())
rotateLegend =
40)) pointLineSize[1] <- 2
if (is.na(pointLineSize[2]) | (pointLineSize[2] < 0) | (pointLineSize[2] > 40)) pointLineSize[2] <- 0.5
if (is.na(pointLineSize[3]) | (pointLineSize[3] < 0) | (pointLineSize[3] > 10)) pointLineSize[3] <- 0.1
if (is.na(alphaValue[1]) | (alphaValue[1] < 0) | (alphaValue[1] > 1)) pointLineSize[1] <- 1
if (is.na(alphaValue[2]) | (alphaValue[2] < 0) | (alphaValue[2] > 1)) pointLineSize[2] <- 0.5
if (is.na(alphaValue[3]) | (alphaValue[3] < 0) | (alphaValue[3] > 1)) pointLineSize[3] <- 0.5
if (is.na(plotTitle)) plotTitle <- NULL #default if no title is given
if (is.na(plotTextSize[1]) | (plotTextSize[1] < 0) | (plotTextSize[1] > 40)) plotTextSize[1] <- 14
if (is.na(plotTitleSize[1]) | (plotTitleSize[1] < 0) | (plotTitleSize[1] > 5)) plotTitleSize[1] <- 1.2
if (is.na(xAxisLabel)) xAxisLabel <- NULL
if (is.na(yAxisLabel)) yAxisLabel <- NULL
if (is.na(xAngle)) xAngle <- 0
if (is.na(axisTextSizeFactorX[1]) | (axisTextSizeFactorX[1] < 0) | (axisTextSizeFactorX[1] > 5)) axisTextSizeFactorX[1] <- 1.0
if (is.na(axisTextSizeFactorX[2]) | (axisTextSizeFactorX[2] < 0) | (axisTextSizeFactorX[2] > 5)) axisTextSizeFactorX[2] <- 0.8
if (is.na(axisTextSizeFactorY[1]) | (axisTextSizeFactorY[1] < 0) | (axisTextSizeFactorY[1] > 5)) axisTextSizeFactorY[1] <- 1
if (is.na(axisTextSizeFactorY[2]) | (axisTextSizeFactorY[2] < 0) | (axisTextSizeFactorY[2] > 5)) axisTextSizeFactorY[2] <- 0.8
if (is.na(yAxisScale[1]) | is.na(yAxisScale[2])) yAxisScale <- NULL
if (useParameterYnameAsAxisLabel) yAxisLabel <- barHeight
if (is.na(legendCoordinate[1]) | is.na(legendCoordinate[2]) | (legendCoordinate[1] < 0) | (legendCoordinate[1] > 1) | (legendCoordinate[2] < 0) | (legendCoordinate[2] > 1)) useLegendCoordinate <- FALSE
if (is.na(legendTextSizeFactor[1]) | (legendTextSizeFactor[1] < 0) | (legendTextSizeFactor[1] > 5)) legendTextSizeFactor[1] <- 0.8
if (is.na(legendTextSizeFactor[2]) | (legendTextSizeFactor[2] < 0) | (legendTextSizeFactor[2] > 5)) legendTextSizeFactor[2] <- 0.8
if (xAngle == 0 ) xAxisAjust <- c(0.5,1.0) #xAxisAjust = c(hjust,vjust)
if (xAngle == 45) xAxisAjust <- c(1.0,1.0)
if (xAngle == 90) xAxisAjust <- c(1.0,0.5)
#2.3 calculate
# create rowID column if needed
if("-ROW ID-" %in% xFactorCol) kIn[,"-ROW ID-"] <- rownames(kIn)
# combine columns if necessary
if(length(xFactor) > 1) {
xFactorCol <- paste(xFactor, collapse = " + ")
kIn[,xFactorCol] <- apply(kIn[,xFactor], 1, paste, collapse = " + ")
}
if(length(facetBy) > 1) {
facetCol <- paste(facetBy, collapse = " + ")
kIn[,facetCol] <- apply(kIn[,facetBy], 1, paste, collapse = " + ")
}
if(length(colourBy) > 1) {
colourCol <- paste(colourBy, collapse = " + ")
kIn[,colourCol] <- apply(kIn[,colourBy], 1, paste, collapse = " + ")
}
# extract necessary data and reshape it
meanData <- kIn[,c(barHeight,xFactorCol, facetCol, colourCol)]
meanDataLong <- melt(meanData, measure.vars = barHeight, variable_name = "- PARAMETERS -")
names(meanDataLong)[which(names(meanDataLong) == "value")] <- "height"
#check if values/data is there, to prevent R error message
if(length(which(!is.na(meanDataLong$height))) == 0){
meanDataLong$height[1] <- 0
plotErrorMessage <- TRUE
} else {
plotErrorMessage <-FALSE
}
# add errorbar data
if(plot.Errorbars) {
sdData <- kIn[,c(barError,xFactorCol, facetCol, colourCol)]
sdDataLong <- melt(sdData, measure.vars = barError)
meanDataLong$error <- sdDataLong$value
if(plot.Errorbars.Negative) {
meanDataLong$low <- with(meanDataLong, height - error)
} else {
meanDataLong$low <- with(meanDataLong, height)
}
if(plot.Errorbars.Plus) {
meanDataLong$high <- with(meanDataLong, height + error)
} else {
meanDataLong$high <- with(meanDataLong, height)
}
if(yAxisScaleLog10) {
meanDataLong[which(meanDataLong$low < 0),"low"] <- 0.000000001
}
}
if(xFactorFlag) xFactorCol <- "- PARAMETERS -"
if(facetFlag) facetCol <- "- PARAMETERS -"
if(colourFlag) colourCol <- "- PARAMETERS -"
if(is.na(legendTitle)) legendTitle <- colourCol #default if no title is given
if(!is.null(facetBy)) {
facetTitle <- facetCol
meanDataLong$template.facet.column <- meanDataLong[,facetCol]
facetCol <- "template.facet.column"
}
if (is.null(colourCol)) { #set grouping column for line plot
groupData <- "- PARAMETERS -"
} else {
groupData <- colourCol
}
if(!is.null(colourBy)) meanDataLong[,colourCol] <- factor(meanDataLong[,colourCol])
#convert to discrete format
#meanDataLong[,xFactorCol] <- factor(meanDataLong[,xFactorCol])
#meanDataLong[,"ggplot_groupid"] <- 1 : nrow(meanDataLong) # variable colourCol needs to be replaced with ggplot_groupid
#2.4.1 plot
p <- ggplot(meanDataLong, aes(x = get(xFactorCol), y = height, group = colourCol))
my.dodge <- position_dodge(width=0.9)
if(!is.null(colourBy)) {
if(plotPointsLines == "points_and_lines" || plotPointsLines == "points_only") {
p <- p + geom_point(aes(colour = factor(get(colourCol))), position = my.dodge, size = pointLineSize[1], alpha = alphaValue[1])}
if(plotPointsLines == "points_and_lines" || plotPointsLines == "lines_only") {
p <- p + geom_line(aes(colour = factor(get(colourCol)), group = get(groupData)), size = pointLineSize[2], alpha = alphaValue[2])}
if(plot.Errorbars) {
p <- p + geom_errorbar(aes(colour = factor(get(colourCol)), ymin = low, ymax = high, group = get(colourCol)), width = pointLineSize[3], alpha = alphaValue[3])}
} else {
if(plotPointsLines == "points_and_lines" || plotPointsLines == "points_only") {
p <- p + geom_point(colour = "black", position = my.dodge, size = pointLineSize[1], alpha = alphaValue[1])}
if(plotPointsLines == "points_and_lines" || plotPointsLines == "lines_only") {
p <- p + geom_line(aes(group = get(groupData)), colour = "black", size = pointLineSize[2], alpha = alphaValue[2])}
if(plot.Errorbars) {
p <- p + geom_errorbar(aes(ymin = low, ymax = high), colour = "black", width = pointLineSize[3], alpha = alphaValue[3])}
}
if(!is.null(facetBy)) {
p <- p + facet_wrap(~ template.facet.column, nrow = twoDgridRow, ncol = twoDgridColumn, scales=free.scales)
fTitle <- paste("Grid factor: ",facetTitle,sep = "")
if(!is.null(plotTitle)) plotTitle <- paste(plotTitle,fTitle,sep = " / ") else plotTitle <- fTitle
p <- p + ggtitle(plotTitle)
} else {
if(!is.null(plotTitle)) p <- p + ggtitle(plotTitle)
}
#2.4.1 layout plot
#general
if(plotTheme == "grey") p <- p + theme_grey(base_size=plotTextSize[1])
if(plotTheme == "black-white") p <- p + theme_bw(base_size=plotTextSize[1])
if(plotTheme == "linedraw") p <- p + theme_linedraw(base_size=plotTextSize[1])
if(plotTheme == "light") p <- p + theme_light(base_size=plotTextSize[1])
if(plotTheme == "classic") p <- p + theme_classic(base_size=plotTextSize[1])
#2.4.2 set general layout of plot
#title options
p <- p + theme(plot.title = element_text(size = plotTextSize[1] * plotTitleSize[1]))
#axis label options
if (useParameterXnameAsAxisLabel) xAxisLabel <- xFactorCol
p <- p + labs(x = xAxisLabel, y = yAxisLabel)
p <- p + theme(axis.title.x = element_text(size = plotTextSize[1] * axisTextSizeFactorX[1]), axis.title.y = element_text(size = plotTextSize[1] * axisTextSizeFactorY[1]))
p <- p + theme(axis.text.x = element_text(angle = xAngle, hjust = xAxisAjust[1], vjust = xAxisAjust[2], size = plotTextSize[1] * axisTextSizeFactorX[2]), axis.text.y = element_text(size = plotTextSize[1] * axisTextSizeFactorY[2]))
# fixing the y-axis labeling, make parameter name or custom y-axis label instead of "height", only if no multi-parameteric plot and only if no y-Axis label was added in the GUI
if(((!is.null(facetBy) && "-USE COLUMN SELECTION-" %in% facetBy )|| length(barHeight) > 1) && is.null(yAxisLabel)) yAxisLabel <- "height"
if(useManualYaxisScale) p <- p + coord_cartesian(ylim = yAxisScale)
if(useManualXaxisScale) p <- p + coord_cartesian(xlim = xAxisScale)
#if(!is.null(xAxisLabel)) p <- p + scale_x_continuous(name = xAxisLabel) # do normal y-axis
if(yAxisScaleLog10) {
p <- p + scale_y_log10(name = yAxisLabel) # do y-axis in log 10 scale
if(yAxisTextLog10) p <- p + scale_y_log10(name = yAxisLabel, breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x)))
} else {
p <- p + scale_y_continuous(name = yAxisLabel) # do normal y-axis
if(yAxisTextLog10) p <- p + scale_y_continuous(name = yAxisLabel, breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x)))
}
# color model checks: is it available? is it defined for the grouping column?
if(useKNIMEColors && !exists("kIn.color.model")) {
stop("No KNIME color model provided. Script was stopped!")
useKNIMEColors <- FALSE
}
if(useKNIMEColors && names(kIn.color.model[1]) != colourCol) {
stop(paste("KNIME color model is different (", names(kIn.color.model[1]), ") from selected color grouping column (", colourCol, ") in template. Script was stopped!"))
useKNIMEColors <- FALSE
}
if(useKNIMEColors) {
kIn.color.model$color <- as.character(kIn.color.model$color)
colourCol <- names(kIn.color.model)[1]
factorColors <- kIn.color.model[,2]
names(factorColors) <- kIn.color.model[,1]
}
# color settings
if(useKNIMEColors) {
p <- p + scale_color_manual(name = colourCol, values = factorColors)
p <- p + scale_fill_manual(name = colourCol, values = factorColors)
} else {
if(colorPalette == "ggplot default") {
p <- p + scale_color_discrete(name = colourCol)
p <- p + scale_fill_discrete(name = colourCol)
} else {
p <- p + scale_color_brewer(name = colourCol, palette = colorPalette)
p <- p + scale_fill_brewer(name = colourCol, palette = colorPalette)
}
}
#legend: legend title, text style and rotation
p <- p + guides(color = guide_legend(title = legendTitle), fill = guide_legend(title = legendTitle)) + theme(legend.title = element_text(size = plotTextSize[1] * legendTextSizeFactor[1], face = "bold"), legend.text = element_text(size = plotTextSize[1] * legendTextSizeFactor[2]))
if(rotateLegend) p <- p + guides(fill = guide_legend(title = legendTitle, direction = "horizontal", title.position = "top", label.position = "bottom", label.hjust = 0.5, label.vjust = 0.5, label.theme = element_text(angle = 90)))
if (useLegendCoordinate) {
p <- p + theme(legend.position = legendCoordinate, legend.background = element_rect(fill = "transparent",colour = NA))
} else {
p <- p + theme(legend.position = legendPosition)
}
if(plotErrorMessage) p <- p + ggtitle("ERROR: NO DATA!!!")
print(p)
]]>
########################################################################################
# name: All-in-one plot (beta)
# author: Martin Stoeter, modified from Antje Niederleins' Barplot
# category: scatterplots
# preview: all-in-one-pl.png
Flexible template to create a scatter plot or scatter plot grid with optional errorbars
In contrary to the LinePlot template, where categorial values are restriced to the x-axis, here numerical values have to be used to have a real scatter plot
HINT: use GroupBy node to aggregated the data to e.g mean and sd columns
Parameter:
x-axis - one numerical variable for x-axis
y-axis - One or multiple numerical variables that will be plotted as y-axis
Error bar checkbox - Draw errorbars?
Error bar - Error bar values corresponding to the y-axis values (same number of columns have to be selected)
To use a flow variable check box and type in variable names using the format: FLOWVAR(variable name)
2D-grid grouping parameter - Allows to split the dataset into multiple plots by this condition (multiple columns can be selected to combine information)
coloured by - Colour of points and lines by condition (mulitple columns can be selected to combine information)
Layout Options:
- select background/theme and set general font size in plot (default = 14)
- plot points or lines or both
- set size and alpha value (transparency) of points, lines and error bars; for no stroke of points set stroke size to 0 (default = [2,0.5,0.1,0.5] and [1,0.5,0.5])
- select different color models for the plot (see: http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/#rcolorbrewer-palette-chart )
- optional the rows and columns can be defined for the 2D grid
- give plot title, title factor (default = 1.2) and alignment
- x-axis text: angle, text size factor for x-/y-axis (default = 0.8)
- y-axis title (or use parameter name: for 2D grid => 'height'), x-axis title, axis title factor (default = 1.0)
- adjust y-axis scale (check fixed and enter min + max; free for 2D grid)
- give legend title, adjust position (fixed position outside diagram or free(range:0-1): [0.1,0.9] = top-left) and legend title/text size factor(default = 0.8)
######
$$$TEMPLATE_DESC$$$
#1.0 Parameter selection
#R debugging: delete all variables except kIn
#rm(list=ls(all=TRUE)[which(ls(all=TRUE) != "kIn")])
plotType =
# Define your numerical parameters represented by y-axis
barHeight = c()
# Define your numerical parameters for error bars
plot.Errorbars =
plot.Errorbars.Plus =
plot.Errorbars.Negative =
barError = c()
#define use of flow variables
# x-axis, grid and color group
xFactor = c()
facetBy = c()
colourBy = c()
#define x-axis for scatter plot
xFactorScatter =
#diagram options
plotPointsLines =
pointLineSize = as.numeric(c())
alphaValue = as.numeric(c())
plotTheme =
plotTextSize = as.numeric(c())
twoDgridRow = c()
twoDgridColumn = c()
plotTitleSize = as.numeric(c())
plotTitleHadjust =
xAngle = as.numeric(c())
axisTextSizeFactor = as.numeric(c())
useParameternameAsAxisLabel =
axisTitleSizeFactor = as.numeric(c())
useManualYaxisScale =
yAxisScale = as.numeric(c())
free.scales =
yAxisScaleLog10 =
yAxisTextLog10 =
lineTypeH =
lineOptionsH = c()
legendPosition =
useLegendCoordinate =
legendCoordinate = as.numeric(c())
legendTitle =
legendTextSizeFactor = as.numeric(c())
rotateLegend =
40)) pointLineSize[1] <- 2
if (is.na(pointLineSize[2]) | (pointLineSize[2] < 0) | (pointLineSize[2] > 40)) pointLineSize[2] <- 0.5
if (is.na(pointLineSize[3]) | (pointLineSize[3] < 0) | (pointLineSize[3] > 10)) pointLineSize[3] <- 0.1
if (is.na(alphaValue[1]) | (alphaValue[1] < 0) | (alphaValue[1] > 1)) pointLineSize[1] <- 1
if (is.na(alphaValue[2]) | (alphaValue[2] < 0) | (alphaValue[2] > 1)) pointLineSize[2] <- 0.5
if (is.na(alphaValue[3]) | (alphaValue[3] < 0) | (alphaValue[3] > 1)) pointLineSize[3] <- 0.5
if (is.na(plotTitle)) plotTitle <- NULL #default if no title is given
if (is.na(plotTextSize[1]) | (plotTextSize[1] < 0) | (plotTextSize[1] > 40)) plotTextSize[1] <- 14
if (is.na(plotTitleSize[1]) | (plotTitleSize[1] < 0) | (plotTitleSize[1] > 5)) plotTitleSize[1] <- 1.2
if (is.na(xAngle)) xAngle <- 0
if (is.na(axisTextSizeFactor[1]) | (axisTextSizeFactor[1] < 0) | (axisTextSizeFactor[1] > 5)) axisTextSizeFactor[1] <- 0.8
if (is.na(axisTextSizeFactor[2]) | (axisTextSizeFactor[2] < 0) | (axisTextSizeFactor[2] > 5)) axisTextSizeFactor[2] <- 0.8
if (is.na(axisTitleSizeFactor[1]) | (axisTitleSizeFactor[1] < 0) | (axisTitleSizeFactor[1] > 5)) axisTitleSizeFactor[1] <- 1
if (is.na(axisTitleSizeFactor[2]) | (axisTitleSizeFactor[2] < 0) | (axisTitleSizeFactor[2] > 5)) axisTitleSizeFactor[2] <- 1
if (is.na(yAxisScale[1]) | is.na(yAxisScale[2])) yAxisScale <- NULL
if (is.na(legendCoordinate[1]) | is.na(legendCoordinate[2]) | (legendCoordinate[1] < 0) | (legendCoordinate[1] > 1) | (legendCoordinate[2] < 0) | (legendCoordinate[2] > 1)) useLegendCoordinate <- FALSE
if (is.na(legendTextSizeFactor[1]) | (legendTextSizeFactor[1] < 0) | (legendTextSizeFactor[1] > 5)) legendTextSizeFactor[1] <- 0.8
if (is.na(legendTextSizeFactor[2]) | (legendTextSizeFactor[2] < 0) | (legendTextSizeFactor[2] > 5)) legendTextSizeFactor[2] <- 0.8
if (xAngle == 0 ) xAxisAjust <- c(0.5,1.0) #xAxisAjust = c(hjust,vjust)
if (xAngle == 45) xAxisAjust <- c(1.0,1.0)
if (xAngle == 90) xAxisAjust <- c(1.0,0.5)
if (plotTitleHadjust == "left") plotTitleHadjust <- 0
if (plotTitleHadjust == "center") plotTitleHadjust <- 0.5
if (plotTitleHadjust == "right") plotTitleHadjust <- 1
#2.3 calculate
# create rowID column if needed
if("-ROW ID-" %in% xFactorCol) kIn[,"-ROW ID-"] <- rownames(kIn)
# combine columns if necessary
if(length(xFactor) > 1) {
xFactorCol <- paste(xFactor, collapse = " + ")
kIn[,xFactorCol] <- apply(kIn[,xFactor], 1, paste, collapse = " + ")
}
if(length(facetBy) > 1) {
facetCol <- paste(facetBy, collapse = " + ")
kIn[,facetCol] <- apply(kIn[,facetBy], 1, paste, collapse = " + ")
}
if(length(colourBy) > 1) {
colourCol <- paste(colourBy, collapse = " + ")
kIn[,colourCol] <- apply(kIn[,colourBy], 1, paste, collapse = " + ")
}
# extract necessary data and reshape it
meanData <- kIn[,c(barHeight,xFactorCol, facetCol, colourCol)]
meanDataLong <- melt(meanData, measure.vars = barHeight, variable_name = "- PARAMETERS -")
names(meanDataLong)[which(names(meanDataLong) == "value")] <- "height"
#check if values/data is there, to prevent R error message
if(length(which(!is.na(meanDataLong$height))) == 0){
meanDataLong$height[1] <- 0
plotErrorMessage <- TRUE
} else {
plotErrorMessage <-FALSE
}
# add errorbar data
if(plot.Errorbars) {
sdData <- kIn[,c(barError,xFactorCol, facetCol, colourCol)]
sdDataLong <- melt(sdData, measure.vars = barError)
meanDataLong$error <- sdDataLong$value
if(plot.Errorbars.Negative) {
meanDataLong$low <- with(meanDataLong, height - error)
} else {
meanDataLong$low <- with(meanDataLong, height)
}
if(plot.Errorbars.Plus) {
meanDataLong$high <- with(meanDataLong, height + error)
} else {
meanDataLong$high <- with(meanDataLong, height)
}
if(yAxisScaleLog10) {
meanDataLong[which(meanDataLong$low < 0),"low"] <- 0.000000001
}
}
if(xFactorFlag) xFactorCol <- "- PARAMETERS -"
if(facetFlag) facetCol <- "- PARAMETERS -"
if(colourFlag) colourCol <- "- PARAMETERS -"
if(!is.null(facetBy)) {
facetTitle <- facetCol
meanDataLong$template.facet.column <- meanDataLong[,facetCol]
facetCol <- "template.facet.column"
}
if (is.null(colourCol)) { #set grouping column for line plot
groupData <- "- PARAMETERS -"
} else {
groupData <- colourCol
}
if(!is.null(colourBy)) meanDataLong[,colourCol] <- factor(meanDataLong[,colourCol])
if(is.na(xAxisLabel)) xAxisLabel <- xFactorCol #default if no x-axis title is given
if(useParameternameAsAxisLabel) yAxisLabel <- barHeight #default if use parameter name is checked
if(is.na(yAxisLabel)) yAxisLabel <- NULL #default if no y-axis title is given
if(is.na(legendTitle)) legendTitle <- colourCol #default if no legend title is given
#convert to discrete format
#meanDataLong[,xFactorCol] <- factor(meanDataLong[,xFactorCol])
#meanDataLong[,"ggplot_groupid"] <- 1 : nrow(meanDataLong) # variable colourCol needs to be replaced with ggplot_groupid
#2.4.1 plot
p <- ggplot(meanDataLong, aes(x = get(xFactorCol), y = height, group = colourCol))
my.dodge <- position_dodge(width=0.9)
if(!is.null(colourBy)) {
if(plotPointsLines == "points_and_lines" || plotPointsLines == "points_only") {
if (pointLineSize[4] < 0.5) {
p <- p + geom_point(aes(colour = factor(get(colourCol))), position = my.dodge, size = pointLineSize[1], alpha = alphaValue[1])
} else {
p <- p + geom_point(aes(fill = factor(get(colourCol))), shape = 21, colour = "black", stroke = pointLineSize[4], position = my.dodge, size = pointLineSize[1], alpha = alphaValue[1])
}
}
if(plotPointsLines == "points_and_lines" || plotPointsLines == "lines_only") {
p <- p + geom_line(aes(colour = factor(get(colourCol)), group = get(groupData)), size = pointLineSize[2], alpha = alphaValue[2])}
if(plot.Errorbars) {
p <- p + geom_errorbar(aes(colour = factor(get(colourCol)), ymin = low, ymax = high, group = get(colourCol)), width = pointLineSize[3], alpha = alphaValue[3])}
} else {
if(plotPointsLines == "points_and_lines" || plotPointsLines == "points_only") {
p <- p + geom_point(colour = "black", position = my.dodge, size = pointLineSize[1], alpha = alphaValue[1])}
if(plotPointsLines == "points_and_lines" || plotPointsLines == "lines_only") {
p <- p + geom_line(aes(group = get(groupData)), colour = "black", size = pointLineSize[2], alpha = alphaValue[2])}
if(plot.Errorbars) {
p <- p + geom_errorbar(aes(ymin = low, ymax = high), colour = "black", width = pointLineSize[3], alpha = alphaValue[3])}
}
if(!is.null(facetBy)) {
p <- p + facet_wrap(~ template.facet.column, nrow = twoDgridRow, ncol = twoDgridColumn, scales=free.scales)
fTitle <- paste("Grid factor: ",facetTitle,sep = "")
if(!is.null(plotTitle)) plotTitle <- paste(plotTitle,fTitle,sep = " / ") else plotTitle <- fTitle
p <- p + ggtitle(plotTitle)
} else {
if(!is.null(plotTitle)) p <- p + ggtitle(plotTitle)
}
#2.4.1 layout plot
#general
if(plotTheme == "grey") p <- p + theme_grey(base_size=plotTextSize[1])
if(plotTheme == "black-white") p <- p + theme_bw(base_size=plotTextSize[1])
if(plotTheme == "linedraw") p <- p + theme_linedraw(base_size=plotTextSize[1])
if(plotTheme == "light") p <- p + theme_light(base_size=plotTextSize[1])
if(plotTheme == "classic") p <- p + theme_classic(base_size=plotTextSize[1])
#2.4.2 set general layout of plot
#title options
p <- p + theme(plot.title = element_text(size = plotTextSize[1] * plotTitleSize[1], hjust = plotTitleHadjust))
#axis label options
p <- p + labs(x = xAxisLabel, y = yAxisLabel)
p <- p + theme(axis.title.x = element_text(size = plotTextSize[1] * axisTitleSizeFactor[1]), axis.title.y = element_text(size = plotTextSize[1] * axisTitleSizeFactor[2]))
p <- p + theme(axis.text.x = element_text(angle = xAngle, hjust = xAxisAjust[1], vjust = xAxisAjust[2], size = plotTextSize[1] * axisTextSizeFactor[1]), axis.text.y = element_text(size = plotTextSize[1] * axisTextSizeFactor[2]))
# fixing the y-axis labeling, make parameter name or custom y-axis label instead of "height", only if no multi-parameteric plot and only if no y-Axis label was added in the GUI
if(((!is.null(facetBy) && "-USE COLUMN SELECTION-" %in% facetBy )|| length(barHeight) > 1) && is.null(yAxisLabel)) yAxisLabel <- "height"
if(useManualYaxisScale) p <- p + coord_cartesian(ylim = yAxisScale)
if(yAxisScaleLog10) {
p <- p + scale_y_log10(name = yAxisLabel) # do y-axis in log 10 scale
if(yAxisTextLog10) p <- p + scale_y_log10(name = yAxisLabel, breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x)))
} else {
p <- p + scale_y_continuous(name = yAxisLabel) # do normal y-axis
if(yAxisTextLog10) p <- p + scale_y_continuous(name = yAxisLabel, breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x)))
}
# color model checks: is it available? is it defined for the grouping column?
if(useKNIMEColors && !exists("kIn.color.model")) {
stop("No KNIME color model provided. Script was stopped!")
useKNIMEColors <- FALSE
}
if(useKNIMEColors && names(kIn.color.model[1]) != colourCol) {
stop(paste("KNIME color model is different (", names(kIn.color.model[1]), ") from selected color grouping column (", colourCol, ") in template. Script was stopped!"))
useKNIMEColors <- FALSE
}
if(useKNIMEColors) {
kIn.color.model$color <- as.character(kIn.color.model$color)
colourCol <- names(kIn.color.model)[1]
factorColors <- kIn.color.model[,2]
names(factorColors) <- kIn.color.model[,1]
}
# color settings
if(useKNIMEColors) {
p <- p + scale_color_manual(name = colourCol, values = factorColors)
p <- p + scale_fill_manual(name = colourCol, values = factorColors)
} else {
if(colorPalette == "ggplot default") {
p <- p + scale_color_discrete(name = colourCol)
p <- p + scale_fill_discrete(name = colourCol)
} else {
p <- p + scale_color_brewer(name = colourCol, palette = colorPalette)
p <- p + scale_fill_brewer(name = colourCol, palette = colorPalette)
}
}
#additional lines like horizontal or vertical
if (lineTypeH != "blanck") p <- p + geom_hline(linetype = lineTypeH, yintercept = as.numeric(lineOptionsH[1]), color = lineOptionsH[2], size = as.numeric(lineOptionsH[3]))
#if (addLine == "vertial") p <- p + geom_vline(linetype = lineType, xintercept = as.numeric(lineOptions[1]), color = lineOptions[2], size = as.numeric(lineOptions[3]))
#legend: legend title, text style and rotation
p <- p + guides(color = guide_legend(title = legendTitle), fill = guide_legend(title = legendTitle)) + theme(legend.title = element_text(size = plotTextSize[1] * legendTextSizeFactor[1], face = "bold"), legend.text = element_text(size = plotTextSize[1] * legendTextSizeFactor[2]))
if(rotateLegend) p <- p + guides(fill = guide_legend(title = legendTitle, direction = "horizontal", title.position = "top", label.position = "bottom", label.hjust = 0.5, label.vjust = 0.5, label.theme = element_text(angle = 90)))
if (useLegendCoordinate) {
p <- p + theme(legend.position = legendCoordinate, legend.background = element_rect(fill = "transparent",colour = NA))
} else {
p <- p + theme(legend.position = legendPosition)
}
if(plotErrorMessage) p <- p + ggtitle("ERROR: NO DATA!!!")
print(p)
]]>
########################################################################################
# name: Plot image positions in well (beta)
# author: Martin Stoeter
# category: utilities
# preview: imagePositionsInWell.png
This template plots image positions within the well. Image positions X and Y can be extracted from .mes files from CV7000 using XML Reader node. The images will be visualized as dashed rectangle, multiple barcodes as colors.
Parameter:
Position x - one numerical variable for x-position of image (center of field in x)
Position y - one numerical variable for y-position of image (center of field in y)
Barcode - text variable with barcode or file name for different .mes files
Objective - select CV7000 objective (60xW, 40x, 20x, 10x or 4x determins size of visualized field)
Well type - determins canvas size of visualized fields (= well size)
Layout Options:
- select background/theme and set general font size in plot (default = 20)
- give plot title and title factor (default = 1.2)
- give legend title, adjust position (fixed position outside diagram or free(range:0-1): [0.1,0.9] = top-left) and legend title/text size factor(default = 0.8)
######
$$$TEMPLATE_DESC$$$
#1.0 Parameter selection
#R debugging: delete all variables except kIn
#rm(list=ls(all=TRUE)[which(ls(all=TRUE) != "kIn")])
# Define numerical parameters for x and y position
columnNameX =
columnNameY =
# Define column for barcode or .mes file name
columnNameBarcode =
# Define well parameters
objective =
wellType =
wellDiameter = as.numeric(c())
#diagram options
plotTheme =
plotTextSize = as.numeric(c())
plotTitleSize = as.numeric(c())
legendPosition =
useLegendCoordinate =
legendCoordinate = as.numeric(c())
legendTitle =
legendTextSizeFactor = as.numeric(c())
rotateLegend =
40)) plotTextSize[1] <- 14
if (is.na(plotTitleSize[1]) | (plotTitleSize[1] < 0) | (plotTitleSize[1] > 5)) plotTitleSize[1] <- 1.2
if (is.na(legendCoordinate[1]) | is.na(legendCoordinate[2]) | (legendCoordinate[1] < 0) | (legendCoordinate[1] > 1) | (legendCoordinate[2] < 0) | (legendCoordinate[2] > 1)) useLegendCoordinate <- FALSE
if (is.na(legendTextSizeFactor[1]) | (legendTextSizeFactor[1] < 0) | (legendTextSizeFactor[1] > 5)) legendTextSizeFactor[1] <- 0.8
if (is.na(legendTextSizeFactor[2]) | (legendTextSizeFactor[2] < 0) | (legendTextSizeFactor[2] > 5)) legendTextSizeFactor[2] <- 0.8
#2.3 calculate
#2.4.1 plot
p <- ggplot(kIn, aes(X, Y, width = width, height = height))
p <- p + geom_tile(aes(colour = barcode), alpha = 0.1, linetype = "dotted", size = 1)
p <- p + coord_cartesian(xlim = c(-wellDiameterX/2, wellDiameterX/2), ylim = c(-wellDiameterY/2, wellDiameterY/2))
if(!is.null(plotTitle)) p <- p + ggtitle(plotTitle)
#2.4.1 layout plot
#general
if(plotTheme == "grey") p <- p + theme_grey(base_size=plotTextSize[1])
if(plotTheme == "black-white") p <- p + theme_bw(base_size=plotTextSize[1])
if(plotTheme == "linedraw") p <- p + theme_linedraw(base_size=plotTextSize[1])
if(plotTheme == "light") p <- p + theme_light(base_size=plotTextSize[1])
if(plotTheme == "classic") p <- p + theme_classic(base_size=plotTextSize[1])
#2.4.2 set general layout of plot
#title options
p <- p + theme(plot.title = element_text(size = plotTextSize[1] * plotTitleSize[1]))
#legend: legend title, text style and rotation
p <- p + guides(fill = guide_legend(title = legendTitle)) + theme(legend.title = element_text(size = plotTextSize[1] * legendTextSizeFactor[1], face = "bold"), legend.text = element_text(size = plotTextSize[1] * legendTextSizeFactor[2]))
if(rotateLegend) p <- p + guides(fill = guide_legend(title = legendTitle, direction = "horizontal", title.position = "top", label.position = "bottom", label.hjust = 0.5, label.vjust = 0.5, label.theme = element_text(angle = 90)))
if (useLegendCoordinate) {
p <- p + theme(legend.position = legendCoordinate, legend.background = element_rect(fill = "transparent",colour = NA))
} else {
p <- p + theme(legend.position = legendPosition)
}
print(p)
]]>
########################################################################################
# name: Find Peaks Plot
# author: Martin Stoeter
# category: analysis
# preview: Find_peaks_plot.png
Analyses a sequence of data point and detects peaks therein.
The plot version just a visualizes, the snippet version just outputs the peak table.
######
Custom template to create a line plot with peak detection
https://www.rdocumentation.org/packages/pracma/versions/1.9.9/topics/findpeaks
https://www.mathworks.com/help/signal/ref/findpeaks.html#bufbbs1-2
Arguments
1) x : numerical vector taken as a time series
2) nups : minimum number of increasing steps before a peak is reached
3) ndowns : minimum number of decreasing steps after the peak
4) zeros : can be "+", "-", or "0"; how to interprete succeeding steps of the same value: increasing, decreasing, or special
5) peakpat : define a peak as a regular pattern, such as the default pattern "[+]1,[-]1,"; if a pattern is provided, the parameters nups and ndowns are not taken into account
6) minpeakheight : the minimum (absolute) height a peak has to have to be recognized as such
7) minpeakdistance : the minimum distance (in indices) peaks have to have to be counted
8) threshold : the minimum height difference between a peak and its neighbors. Use this argument to have findpeaks return only those peaks that exceed their immediate neighboring values by at least the value of "threshold"
9) npeaks : the number of peaks to return
10) sortstr : logical; should the peaks be returned sorted in decreasing oreder of their maximum value
Returns a matrix where each row represents one peak found. The first column gives the height, the second the position/index where the maximum is reached, the third and forth the indices of where the peak begins and ends --- in the sense of where the pattern starts and ends.
Parameter:
input data/signal - date series to be used for peak detection
time series - column with time values for series; -USE INDEX- will return the index values (1 to end of series)
signal peak threshold - minimum peak height threshold
delta slope threshold - minimum difference threshold in slope detection (within chosen distance, onset and offset)
delta slope distance - distance value (index) in slope between the difference is calculated
To use a flow variable check box and type in variable names using the format: FLOWVAR(variable name)
Layout Options:
- plot points or lines or both
- set size of points (default = [0.7,2.0,1.5,1.2])
- give plot title and title factor (default = 1.2)
- adjust y-axis scale (enter min + max for y-axis)
#1.0 Parameter selection
#R debugging: delete all variables except kIn
#rm(list=ls(all=TRUE)[which(ls(all=TRUE) != "kIn")])
# Define your numerical parameters for input signal
signalValueColumn =
# Define your numerical parameters for time series
timeColumn =
output = "table"
# delete this line for snippet template, to diaable GUI choise
# Define peak detection parameters
# adjustment parameter, minimum peak height threshold and lower threshold
minPeakHeight = as.numeric()
threshold = as.numeric()
# adjustment parameter, minimum difference in slope (within chosen distance)
minDeltaSlope = as.numeric()
# More/advanced peak definition parameters
# adjustment parameter, distance value (index) in slope between the difference is calculated
distanceDeltaSlope = as.numeric()
# adjustment parameter, minimum number of increasing/decreasing steps before/after a peak is reached
nUpsDowns = as.numeric()
# adjustment parameter, the minimum (absolute) height / distance (indices) peaks has to have to be recognized
minPeakDistance = as.numeric()
#diagram options
plotPointsLines =
pointPointSizes = as.numeric()
plotTitleSize = as.numeric(c())
= minDeltaSlope))
# now start moving left
while (currentSlopeDelta >= minDeltaSlope & currentSlopePosition > 1) {
currentSlopePosition = currentSlopePosition - 1
currentSlopeDelta <- pSignal[currentSlopePosition + distanceDeltaSlope] - pSignal[currentSlopePosition]
#print(c(i, currentPeakPosition, currentSlopePosition, pSignal[currentSlopePosition + distanceDeltaSlope], pSignal[currentSlopePosition], currentSlopeDelta, currentSlopeDelta > minDeltaSlope))
}
peakOnset[i] <- currentSlopePosition + 1 # this vector will contain all peak onset indices
#print(peakOnset)
# find peak offset and move from peak maximum rightwards (higher index) until currentSlopeDelta is smaller than distanceDeltaSlope
currentSlopePosition <- currentPeakPosition + distanceDeltaSlope # currentSlopePosition is positon that is increased and checked iteratively
if(currentSlopePosition >= length(pSignal)) currentSlopePosition = length(pSignal) # if peak is at right edge of signal
currentSlopeDelta <- pSignal[currentPeakPosition] - pSignal[currentSlopePosition]
#print(c(i, currentPeakPosition, currentSlopePosition, pSignal[currentPeakPosition], pSignal[currentSlopePosition], currentSlopeDelta, currentSlopeDelta >= minDeltaSlope))
# now start moving right
while (currentSlopeDelta >= minDeltaSlope & currentSlopePosition < length(pSignal)) {
currentSlopePosition = currentSlopePosition + 1
currentSlopeDelta <- pSignal[currentSlopePosition - distanceDeltaSlope] - pSignal[currentSlopePosition]
#print(c(i, currentPeakPosition, currentSlopePosition, pSignal[currentSlopePosition - distanceDeltaSlope], pSignal[currentSlopePosition], currentSlopeDelta, currentSlopeDelta > minDeltaSlope))
}
peakOffset[i] <- currentSlopePosition - 1 # this vector will contain all peak offset indices
#print(peakOffset)
}
}
# this is the final index-based result table
peakTable <- cbind(peakTable, onset = peakOnset, offset = peakOffset)
# make rOut data frame for returing data to KNIME
rOut <- data.frame(peakTable)
# replace index values (position start end onset offset) with real (time series) values from input table
if (timeColumn != "-USE INDEX-") {
if (rOut[1,"position"] != 0) {
for (col in 2:6) rOut[, col] <- kIn[rOut[, col], timeColumn]
}
}
#2.4.1 layout plot
# plot signal values
if (output == "plot") { # if this is plot template then true, if this is snippet template then false
if (plotPointsLines == "points_and_lines") plotPointsLines <- "o"
if (plotPointsLines == "points_only") plotPointsLines <- "p"
if (plotPointsLines == "lines_only") plotPointsLines <- "l"
plot(x = xValues, y = pSignal, type=plotPointsLines, col="grey40", cex = pointPointSizes[1], ylim = yAxisScale,
main = plotTitle, xlab = xAxisTitle, ylab = signalValueColumn, cex.main = plotTitleSize)
grid()
#2.4.2 plot data
# plot peaks, start, end and values between onset and offset
if (peakTable[1,"position"] != 0) {
for(i in 1:nrow(peakTable)) {
points(kIn[peakTable[i,"onset"]:peakTable[i,"offset"], "xValues"], kIn[peakTable[i,"onset"]:peakTable[i,"offset"], signalValueColumn], pch=20, col="black", cex = pointPointSizes[4])
}
points(kIn[peakTable[,"position"], "xValues"], kIn[peakTable[,"position"], signalValueColumn], pch=24, col="red", cex = pointPointSizes[2])
points(kIn[peakTable[, "start"], "xValues"], kIn[peakTable[, "start"], signalValueColumn], pch=22, col="darkorange", cex = pointPointSizes[3])
points(kIn[peakTable[, "end"], "xValues"], kIn[peakTable[, "end"], signalValueColumn], pch=23, col="darkred", cex = pointPointSizes[3])
}
#2.4.3 plot options
# adds horizontal lines
if (plotThreshold) abline(h = threshold, lty = 2)
if (plotMinPeakHeight) abline(h = minPeakHeight, lty = 3)
#abline(h = hlines[2], lwd = 1.5)
} # end plot data
# debug
#rOut
#peakTable
#findpeaks(pSignal, threshold=threshold, sortstr=TRUE)
]]>