-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotGeneVarianceRangePlot.R
68 lines (53 loc) · 2.09 KB
/
plotGeneVarianceRangePlot.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#'
#' Plot module for variance plot
#'
library(shiny)
library(shinyBS)
library(ggplot2)
source("uiHelper.R")
source("widgetVisualsEditor.R")
plotGeneVarianceRangePlotUI <- function(id, ...) {
ns <- NS(id)
return(verticalLayout(bsButton(ns("logarithmic"),
"Logarithmic",
icon = icon("superscript"),
type = "toggle",
value = T),
hDivider(),
plotOutput(ns("plot"), ...)))
}
plotGeneVarianceRangePlot_ <- function(input,
output,
session,
dataset) {
output$plot <- renderPlot({
validate(need(dataset(), "No gene variances to display!"))
validate(need(dataset()$variances.filtered, "No gene variances to display!"))
logarithmic <- input$logarithmic
genes.count <- dataset()$readcounts.top.variant.parameters.count
data <- dataset()$variances.filtered
data$logvar <- log(data$var)
data.selection <- data[1:genes.count,]
if(logarithmic) {
p <- ggplot(data, aes(x=1:nrow(data), y=logvar))
p <- p + geom_vline(xintercept = genes.count, color = "red")
p <- p + geom_ribbon(data = data.selection, aes(ymin = min(data$logvar), ymax = logvar, x = 1:genes.count), fill = "#da4453")
p <- p + geom_point()
p <- p + labs(x = "Top n-th variant gene", y = expression(log(sigma^2)))
return(p)
}
else {
p <- ggplot(data, aes(x=1:nrow(data), y=var))
p <- p + geom_vline(xintercept = genes.count, color = "red")
p <- p + geom_ribbon(data = data.selection, aes(ymin = min(data$var), ymax = var, x = 1:genes.count), fill = "#da4453")
p <- p + geom_point()
p <- p + labs(x = "Top n-th variant gene", y = expression(sigma^2))
return(p)
}
})
}
plotGeneVarianceRangePlot <- function(id, dataset) {
return(callModule(plotGeneVarianceRangePlot_,
id,
dataset = dataset))
}