From 1c117fea7ec5ce990534f1a939de33dd508c1b71 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Wed, 10 Jan 2018 11:04:31 +0100 Subject: [PATCH 01/25] create_heatmap: param scale added (only working with static) --- R/function.R | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/R/function.R b/R/function.R index 0296f9f..9cc1de7 100644 --- a/R/function.R +++ b/R/function.R @@ -405,11 +405,12 @@ create_pca <- function(data, dimensionA = 1, dimensionB = 2, dimensions = 6, on. #' @param width Set width of plot in cm (Default = "auto"). #' @param height Set height of plot in cm (Default = "auto"). #' @param ppi Pixel per inch (default = 72). +#' @param scale Modify plot size while preserving aspect ratio (Default = 1). #' #' @details Width/ height limit = 500. If exceeded default to 500 and issue exceed_size = TRUE. #' #' @return Returns list(plot = complexHeatmap/ plotly object, width = width in cm, height = height in cm, ppi = pixel per inch, exceed_size = Boolean whether width/ height exceeded max) depending on plot.method. -create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label = NULL, column.label=T, column.custom.label = NULL, clustering='none', clustdist='auto', clustmethod='auto', colors=NULL, winsorize.colors = NULL, plot.method = "static", width = "auto", height = "auto", ppi = 72) { +create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label = NULL, column.label=T, column.custom.label = NULL, clustering='none', clustdist='auto', clustmethod='auto', colors=NULL, winsorize.colors = NULL, plot.method = "static", width = "auto", height = "auto", ppi = 72, scale = 1) { requireNamespace("heatmaply", quietly = TRUE) requireNamespace("ComplexHeatmap", quietly = TRUE) requireNamespace("grDevices", quietly = TRUE) @@ -570,9 +571,9 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label column_dend_height = grid::unit(1, "inches"), row_names_max_width = grid::unit(8, "inches"), column_names_max_height = grid::unit(4, "inches"), - row_names_gp = grid::gpar(fontsize = 12), - column_names_gp = grid::gpar(fontsize = 12), - column_title_gp = grid::gpar(fontsize = 10, units = "in"), + row_names_gp = grid::gpar(fontsize = 12 * scale), + column_names_gp = grid::gpar(fontsize = 12 * scale), + column_title_gp = grid::gpar(fontsize = 10 * scale, units = "in"), heatmap_legend_param = list( color_bar = "continuous", legend_direction = "horizontal" @@ -580,10 +581,10 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label ) #width/ height calculation - col_names_maxlength_label_width=max(sapply(colnames(prep.data), graphics::strwidth, units="in", font=12)) #longest column label when plotted in inches - col_names_maxlength_label_height=max(sapply(colnames(prep.data), graphics::strheight, units="in", font=12)) #highest column label when plotted in inches - row_names_maxlength_label_width=max(sapply(rownames(prep.data), graphics::strwidth, units="in", font=12)) #longest row label when plotted in inches - row_names_maxlength_label_height=max(sapply(rownames(prep.data), graphics::strheight, units="in", font=12)) #highest row label when plotted in inches + col_names_maxlength_label_width=max(sapply(colnames(prep.data), graphics::strwidth, units="in", font = 12)) #longest column label when plotted in inches + col_names_maxlength_label_height=max(sapply(colnames(prep.data), graphics::strheight, units="in", font = 12)) #highest column label when plotted in inches + row_names_maxlength_label_width=max(sapply(rownames(prep.data), graphics::strwidth, units="in", font = 12)) #longest row label when plotted in inches + row_names_maxlength_label_height=max(sapply(rownames(prep.data), graphics::strheight, units="in", font = 12)) #highest row label when plotted in inches # width if(row.label){ @@ -631,7 +632,7 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label height <- 500 } - plot <- list(plot = plot, width = width, height = height, ppi = ppi, exceed_size = exceed_size) + plot <- list(plot = plot, width = width * scale, height = height * scale, ppi = ppi, exceed_size = exceed_size) } return(plot) From 67b2b75db4a8c4b025a9187b623434809b59210a Mon Sep 17 00:00:00 2001 From: Schultheis Date: Wed, 10 Jan 2018 11:18:37 +0100 Subject: [PATCH 02/25] create_heatmap: static -> scale legend fonts aswell --- R/function.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/function.R b/R/function.R index 9cc1de7..c03adb6 100644 --- a/R/function.R +++ b/R/function.R @@ -576,7 +576,9 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label column_title_gp = grid::gpar(fontsize = 10 * scale, units = "in"), heatmap_legend_param = list( color_bar = "continuous", - legend_direction = "horizontal" + legend_direction = "horizontal", + title_gp = grid::gpar(fontsize = 10 * scale), + labels_gp = grid::gpar(fontsize = 8 * scale) ) ) From 8819a8f9e7bca7db936edf3fc9475e928641c4ea Mon Sep 17 00:00:00 2001 From: Schultheis Date: Wed, 10 Jan 2018 11:39:56 +0100 Subject: [PATCH 03/25] create_heatmap: scale legend --- R/function.R | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/R/function.R b/R/function.R index c03adb6..412aac1 100644 --- a/R/function.R +++ b/R/function.R @@ -567,10 +567,10 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label show_column_names = column.label, row_names_side = "left", row_dend_side = "right", - row_dend_width = grid::unit(1, "inches"), - column_dend_height = grid::unit(1, "inches"), - row_names_max_width = grid::unit(8, "inches"), - column_names_max_height = grid::unit(4, "inches"), + row_dend_width = grid::unit(1 * scale, "inches"), + column_dend_height = grid::unit(1 * scale, "inches"), + row_names_max_width = grid::unit(8 * scale, "inches"), + column_names_max_height = grid::unit(4 * scale, "inches"), row_names_gp = grid::gpar(fontsize = 12 * scale), column_names_gp = grid::gpar(fontsize = 12 * scale), column_title_gp = grid::gpar(fontsize = 10 * scale, units = "in"), @@ -578,7 +578,8 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label color_bar = "continuous", legend_direction = "horizontal", title_gp = grid::gpar(fontsize = 10 * scale), - labels_gp = grid::gpar(fontsize = 8 * scale) + labels_gp = grid::gpar(fontsize = 8 * scale), + grid_height = grid::unit(0.15 * scale, "inches") ) ) From bc05d6cbb6bbcb0b02bdcd8672e971f067edeedb Mon Sep 17 00:00:00 2001 From: Schultheis Date: Wed, 10 Jan 2018 14:56:10 +0100 Subject: [PATCH 04/25] create_heatmap: complexHeatmap row_dend_gp (not operational) --- R/function.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/function.R b/R/function.R index 412aac1..3fb529c 100644 --- a/R/function.R +++ b/R/function.R @@ -568,7 +568,9 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label row_names_side = "left", row_dend_side = "right", row_dend_width = grid::unit(1 * scale, "inches"), + # row_dend_gp = grid::gpar(lwd = 1, lex = scale), # don't seem to work column_dend_height = grid::unit(1 * scale, "inches"), + # column_dend_gp = grid::gpar(lwd = 1, lex = scale), # don't seem to work row_names_max_width = grid::unit(8 * scale, "inches"), column_names_max_height = grid::unit(4 * scale, "inches"), row_names_gp = grid::gpar(fontsize = 12 * scale), From d2a8a22555a4ba5a85201c022957a176ff9b6fa5 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Wed, 10 Jan 2018 14:57:13 +0100 Subject: [PATCH 05/25] global_cor_heatmap: param scale added --- R/global_cor_heatmap.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/global_cor_heatmap.R b/R/global_cor_heatmap.R index 4ea4aea..8aada9a 100644 --- a/R/global_cor_heatmap.R +++ b/R/global_cor_heatmap.R @@ -157,13 +157,14 @@ global_cor_heatmapUI <- function(id) { #' @param width Width of the plot in cm. Defaults to minimal size for readable labels and supports reactive. #' @param height Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive. #' @param ppi Pixel per inch. Defaults to 72 and supports reactive. +#' @param scale Scale plot size. Defaults to 1, supports reactive. #' #' #' #' @return Reactive containing data used for plotting. #' #' @export -global_cor_heatmap <- function(input, output, session, data, types, plot.method = "static", width = "auto", height = "auto", ppi = 72) { +global_cor_heatmap <- function(input, output, session, data, types, plot.method = "static", width = "auto", height = "auto", ppi = 72, scale = 1) { # load module ------------------------------------------------------------- # handle reactive data data_r <- shiny::reactive({ @@ -180,6 +181,7 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method width <- ifelse(shiny::is.reactive(width), width(), width) height <- ifelse(shiny::is.reactive(height), height(), height) ppi <- ifelse(shiny::is.reactive(ppi), ppi(), ppi) + scale <- ifelse(shiny::is.reactive(scale), scale(), scale) if(!is.numeric(width) || width <= 0) { width <- "auto" @@ -197,7 +199,8 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method list(width = width, height = height, - ppi = ppi) + ppi = ppi, + scale = scale) }) # load internal modules @@ -346,7 +349,8 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method height = size()$height, ppi = size()$ppi, plot.method = plot.method, - winsorize.colors = colorPicker()$winsorize + winsorize.colors = colorPicker()$winsorize, + scale = size()$scale ) # update progress indicator From fbb0c00fe9dab9583111d3f70dc3962e552271d6 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Wed, 10 Jan 2018 14:58:55 +0100 Subject: [PATCH 06/25] global_cor_heatmap_example: scaleing slider --- exec/global_cor_heatmap_example.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exec/global_cor_heatmap_example.R b/exec/global_cor_heatmap_example.R index 361273b..01d31f5 100644 --- a/exec/global_cor_heatmap_example.R +++ b/exec/global_cor_heatmap_example.R @@ -17,7 +17,8 @@ ui <- dashboardPage( header = dashboardHeader(), sidebar = dashboardSidebar( numericInput(inputId = "width", label = "width in cm", value = 0, min = 0), - numericInput(inputId = "height", label = "height in cm", value = 0, min = 0) + numericInput(inputId = "height", label = "height in cm", value = 0, min = 0), + sliderInput(inputId = "scale", label = "scale plot", value = 1, min = 1, max = 10) ), dashboardBody( fluidPage( @@ -27,7 +28,7 @@ ui <- dashboardPage( ) server <- function(input, output) { - table <- shiny::callModule(global_cor_heatmap, "id", data = data, types = metadata[type %in% c("performance", "design")], plot.method = "static", width = reactive(input$width), height = reactive(input$height)) + table <- shiny::callModule(global_cor_heatmap, "id", data = data, types = metadata[type %in% c("performance", "design")], plot.method = "static", width = reactive(input$width), height = reactive(input$height), scale = reactive(input$scale)) shiny::observe({ print(table()) From df3abcbc2168424e83793bdfb8196c924ac58c48 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Wed, 10 Jan 2018 14:59:34 +0100 Subject: [PATCH 07/25] manuals added --- man/create_heatmap.Rd | 4 +++- man/global_cor_heatmap.Rd | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/man/create_heatmap.Rd b/man/create_heatmap.Rd index e626291..c425135 100644 --- a/man/create_heatmap.Rd +++ b/man/create_heatmap.Rd @@ -8,7 +8,7 @@ create_heatmap(data, unitlabel = "auto", row.label = T, row.custom.label = NULL, column.label = T, column.custom.label = NULL, clustering = "none", clustdist = "auto", clustmethod = "auto", colors = NULL, winsorize.colors = NULL, plot.method = "static", - width = "auto", height = "auto", ppi = 72) + width = "auto", height = "auto", ppi = 72, scale = 1) } \arguments{ \item{data}{data.table containing plot data. First column contains row labels.} @@ -40,6 +40,8 @@ create_heatmap(data, unitlabel = "auto", row.label = T, \item{height}{Set height of plot in cm (Default = "auto").} \item{ppi}{Pixel per inch (default = 72).} + +\item{scale}{Modify plot size while preserving aspect ratio (Default = 1).} } \value{ Returns list(plot = complexHeatmap/ plotly object, width = width in cm, height = height in cm, ppi = pixel per inch, exceed_size = Boolean whether width/ height exceeded max) depending on plot.method. diff --git a/man/global_cor_heatmap.Rd b/man/global_cor_heatmap.Rd index 8f3a512..80e86b8 100644 --- a/man/global_cor_heatmap.Rd +++ b/man/global_cor_heatmap.Rd @@ -5,7 +5,8 @@ \title{global correlation heatmap module server logic} \usage{ global_cor_heatmap(input, output, session, data, types, - plot.method = "static", width = "auto", height = "auto", ppi = 72) + plot.method = "static", width = "auto", height = "auto", ppi = 72, + scale = 1) } \arguments{ \item{input}{Shiny's input object} @@ -29,6 +30,8 @@ column4 = sub_label (optional, added to id/ label)} \item{height}{Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive.} \item{ppi}{Pixel per inch. Defaults to 72 and supports reactive.} + +\item{scale}{Scale plot size. Defaults to 1, supports reactive.} } \value{ Reactive containing data used for plotting. From 8ede3c83862ed2aedbd984ede82c4fdf269d89c6 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 09:28:34 +0100 Subject: [PATCH 08/25] create_heatmap: now working scale with interactive plots --- R/function.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/function.R b/R/function.R index 3fb529c..3dc0e8d 100644 --- a/R/function.R +++ b/R/function.R @@ -459,7 +459,7 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label hclust_method = clustmethod, dist_method = clustdist, dendrogram = clustering, - distfun = factoextra::get_dist + distfun = factoextra::get_dist, #width = width, #not working #height = height ) @@ -482,6 +482,10 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label height <- auto_height } + # add scale + width <- width * scale + height <- height * scale + # size exceeded? exceed_size <- FALSE limit <- 500 * (ppi / 2.54) From 04dbf0b9508446f8db399aebdf223c919ef42c42 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 09:36:47 +0100 Subject: [PATCH 09/25] heatmap: support plot scaleing --- R/heatmap.R | 8 ++++++-- man/heatmap.Rd | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/R/heatmap.R b/R/heatmap.R index c21cf92..a6a7e2c 100644 --- a/R/heatmap.R +++ b/R/heatmap.R @@ -103,11 +103,12 @@ heatmapUI <- function(id, row.label = TRUE) { #' @param width Width of the plot in cm. Defaults to minimal size for readable labels and supports reactive. #' @param height Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive. #' @param ppi Pixel per inch. Defaults to 72 and supports reactive. +#' @param scale Scale plot size. Defaults to 1, supports reactive. #' #' @return Reactive containing data used for plotting. #' #' @export -heatmap <- function(input, output, session, data, types, plot.method = "static", custom.row.label = NULL, label.sep = ", ", width = "auto", height = "auto", ppi = 72) { +heatmap <- function(input, output, session, data, types, plot.method = "static", custom.row.label = NULL, label.sep = ", ", width = "auto", height = "auto", ppi = 72, scale = 1) { # cluster limitation static <- 11000 interactive <- 3000 @@ -125,6 +126,7 @@ heatmap <- function(input, output, session, data, types, plot.method = "static", width <- ifelse(shiny::is.reactive(width), width(), width) height <- ifelse(shiny::is.reactive(height), height(), height) ppi <- ifelse(shiny::is.reactive(ppi), ppi(), ppi) + scale <- ifelse(shiny::is.reactive(scale), scale(), scale) if(!is.numeric(width) || width <= 0) { width <- "auto" @@ -142,7 +144,8 @@ heatmap <- function(input, output, session, data, types, plot.method = "static", list(width = width, height = height, - ppi = ppi) + ppi = ppi, + scale = scale) }) # Fetch the reactive guide for this module @@ -277,6 +280,7 @@ heatmap <- function(input, output, session, data, types, plot.method = "static", width = size()$width, height = size()$height, ppi = size()$ppi, + scale = size()$scale, plot.method = plot.method, winsorize.colors = colorPicker()$winsorize ) diff --git a/man/heatmap.Rd b/man/heatmap.Rd index cd9bd68..077dbf4 100644 --- a/man/heatmap.Rd +++ b/man/heatmap.Rd @@ -6,7 +6,7 @@ \usage{ heatmap(input, output, session, data, types, plot.method = "static", custom.row.label = NULL, label.sep = ", ", width = "auto", - height = "auto", ppi = 72) + height = "auto", ppi = 72, scale = 1) } \arguments{ \item{input}{Shiny's input object} @@ -34,6 +34,8 @@ column4: sub_label (optional, added to id/ label)} \item{height}{Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive.} \item{ppi}{Pixel per inch. Defaults to 72 and supports reactive.} + +\item{scale}{Scale plot size. Defaults to 1, supports reactive.} } \value{ Reactive containing data used for plotting. From 7976c0e0fa00308ae4981e7e7d2a43407598d462 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 09:37:46 +0100 Subject: [PATCH 10/25] heatmap_example: use scaleing --- exec/heatmap_example.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exec/heatmap_example.R b/exec/heatmap_example.R index 53e083b..771c75e 100644 --- a/exec/heatmap_example.R +++ b/exec/heatmap_example.R @@ -18,7 +18,8 @@ names(metadata)[1] <- "key" ui <- dashboardPage(header = dashboardHeader(), sidebar = dashboardSidebar( numericInput(inputId = "width", label = "width in cm", value = 0, min = 0), - numericInput(inputId = "height", label = "height in cm", value = 0, min = 0) + numericInput(inputId = "height", label = "height in cm", value = 0, min = 0), + sliderInput(inputId = "scale", label = "scale plot", value = 1, min = 1, max = 10) ), dashboardBody(fluidPage( heatmapUI("id") ))) @@ -32,7 +33,7 @@ server <- function(input, output) { metadata[ type != "annotation"] }) - heat <- callModule(heatmap, "id", data = table, types = typ, plot.method = "static", custom.row.label = table, width = reactive(input$width), height = reactive(input$height)) + heat <- callModule(heatmap, "id", data = table, types = typ, plot.method = "interactive", custom.row.label = table, width = reactive(input$width), height = reactive(input$height), scale = reactive(input$scale)) observe({ print(heat()) From c7ed1cae20cc57d441001aa91399f2106445ade4 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 12:55:09 +0100 Subject: [PATCH 11/25] create_heatmap: scale texts aswell (interactive); create_geneView: implemented scaleing --- R/function.R | 21 +++++++++++++++------ man/create_geneview.Rd | 4 +++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/R/function.R b/R/function.R index 3dc0e8d..4b5bd13 100644 --- a/R/function.R +++ b/R/function.R @@ -442,7 +442,7 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label if(plot.method == "interactive"){ #estimate label sizes #row label - rowlabel_size <- ifelse(row.label, max(nchar(data[[1]]), na.rm = TRUE) * 8, 0) + rowlabel_size <- ifelse(row.label, max(nchar(data[[1]]), na.rm = TRUE) * 8 * scale, 0) #column label collabel_size <- ifelse(column.label, (2 + log2(max(nchar(names(data)), na.rm = TRUE))^2) * 10, 0) #legend @@ -459,7 +459,7 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label hclust_method = clustmethod, dist_method = clustdist, dendrogram = clustering, - distfun = factoextra::get_dist, + distfun = factoextra::get_dist #width = width, #not working #height = height ) @@ -467,10 +467,14 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label #layout plot <- heatmaply::heatmaply(plot, plot_method = "ggplot", - scale_fill_gradient_fun = ggplot2::scale_fill_gradientn(colors = colors, name = unitlabel, limits = winsorize.colors, oob = scales::squish) + scale_fill_gradient_fun = ggplot2::scale_fill_gradientn(colors = colors, name = unitlabel, limits = winsorize.colors, oob = scales::squish), + heatmap_layers = ggplot2::theme(text = ggplot2::element_text(size = 12 * scale)) ) - plot <- plotly::layout(plot, autosize = ifelse(width == "auto", TRUE, FALSE), margin = list(l = rowlabel_size, r = legend, b = collabel_size)) + # scale axis ticks + ticks <- list(tickfont = list(size = 12 * scale)) + + plot <- plotly::layout(plot, autosize = ifelse(width == "auto", TRUE, FALSE), margin = list(l = rowlabel_size, r = legend, b = collabel_size), xaxis = ticks, yaxis2 = ticks) # decide which sizes should be used if(width == "auto") { @@ -664,13 +668,14 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label #' @param width Set the width of the plot in cm (default = "auto"). #' @param height Set the height of the plot in cm (default = "auto"). #' @param ppi Pixel per inch (default = 72). +#' @param scale Modify plot size while preserving aspect ratio (Default = 1). #' #' @details Width/ height limit = 500. If exceeded default to 500 and issue exceed_size = TRUE. #' #' @import data.table #' #' @return Returns depending on plot.method list(plot = ggplot/ plotly object, width = width in cm, height = height in cm, ppi = pixel per inch, exceed_size = Boolean). -create_geneview <- function(data, grouping, plot.type = "line", facet.target = "gene", facet.cols = 2, colors = NULL, ylabel = NULL, ylimits = NULL, gene.label = NULL, plot.method = "static", width = "auto", height = "auto", ppi = 72){ +create_geneview <- function(data, grouping, plot.type = "line", facet.target = "gene", facet.cols = 2, colors = NULL, ylabel = NULL, ylimits = NULL, gene.label = NULL, plot.method = "static", width = "auto", height = "auto", ppi = 72, scale = 1){ #grouping #group by factor if existing (fill with key if empty) grouping[grouping[[2]] == "", 2 := grouping[grouping[[2]] == "", 1]] @@ -773,7 +778,7 @@ create_geneview <- function(data, grouping, plot.type = "line", facet.target = " legend.position = "none", #remove legend legend.title = ggplot2::element_blank(), axis.title.x = ggplot2::element_blank(), - text = ggplot2::element_text(family = "mono", size = 15) + text = ggplot2::element_text(family = "mono", size = 15 * scale) #axis.line.x = element_line(size = .3), #axis.line.y = element_line(size = .3), @@ -967,6 +972,10 @@ create_geneview <- function(data, grouping, plot.type = "line", facet.target = " height <- auto_height } + # add scaleing factor + width <- width * scale + height <- height * scale + # size exceeded? exceed_size <- FALSE if(width > 500) { diff --git a/man/create_geneview.Rd b/man/create_geneview.Rd index 7117b8a..8ca3d08 100644 --- a/man/create_geneview.Rd +++ b/man/create_geneview.Rd @@ -7,7 +7,7 @@ create_geneview(data, grouping, plot.type = "line", facet.target = "gene", facet.cols = 2, colors = NULL, ylabel = NULL, ylimits = NULL, gene.label = NULL, plot.method = "static", width = "auto", - height = "auto", ppi = 72) + height = "auto", ppi = 72, scale = 1) } \arguments{ \item{data}{data.table containing plot data} @@ -37,6 +37,8 @@ column2 : factor1} \item{height}{Set the height of the plot in cm (default = "auto").} \item{ppi}{Pixel per inch (default = 72).} + +\item{scale}{Modify plot size while preserving aspect ratio (Default = 1).} } \value{ Returns depending on plot.method list(plot = ggplot/ plotly object, width = width in cm, height = height in cm, ppi = pixel per inch, exceed_size = Boolean). From 88a85debfc21ccc8c2575e0a5510a74669d889c3 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 12:57:12 +0100 Subject: [PATCH 12/25] geneView: param scale added --- R/geneView.R | 10 +++++++--- man/geneView.Rd | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/R/geneView.R b/R/geneView.R index 7ce41c8..773c15a 100644 --- a/R/geneView.R +++ b/R/geneView.R @@ -98,6 +98,7 @@ geneViewUI <- function(id, plot.columns = 3){ #' @param width Width of the plot in cm. Defaults to minimal size for readable labels and supports reactive. #' @param height Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive. #' @param ppi Pixel per inch. Defaults to 72 and supports reactive. +#' @param scale Scale plot size. Defaults to 1, supports reactive. #' #' @details Width/ height/ ppi less or equal to default will use default value. #' @details Ppi less or equal to zero will use default. @@ -106,7 +107,7 @@ geneViewUI <- function(id, plot.columns = 3){ #' #' @export -geneView <- function(input, output, session, data, metadata, level = NULL, plot.method = "static", custom.label = NULL, label.sep = ", ", width = "auto", height = "auto", ppi = 72){ +geneView <- function(input, output, session, data, metadata, level = NULL, plot.method = "static", custom.label = NULL, label.sep = ", ", width = "auto", height = "auto", ppi = 72, scale = 1){ #handle reactive data data.r <- shiny::reactive({ if(shiny::is.reactive(data)){ @@ -136,6 +137,7 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot. width <- ifelse(shiny::is.reactive(width), width(), width) height <- ifelse(shiny::is.reactive(height), height(), height) ppi <- ifelse(shiny::is.reactive(ppi), ppi(), ppi) + scale <- ifelse(shiny::is.reactive(scale), scale(), scale) if(!is.numeric(width) || width <= 0) { width <- "auto" @@ -149,7 +151,8 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot. list(width = width, height = height, - ppi = ppi) + ppi = ppi, + scale = scale) }) #Fetch the reactive guide for this module @@ -279,7 +282,8 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot. plot.method = plot.method, width = size()$width, height = size()$height, - ppi = size()$ppi + ppi = size()$ppi, + scale = size()$scale ) progress$set(1, detail = "Return plot") diff --git a/man/geneView.Rd b/man/geneView.Rd index b33b235..b8e755d 100644 --- a/man/geneView.Rd +++ b/man/geneView.Rd @@ -6,7 +6,7 @@ \usage{ geneView(input, output, session, data, metadata, level = NULL, plot.method = "static", custom.label = NULL, label.sep = ", ", - width = "auto", height = "auto", ppi = 72) + width = "auto", height = "auto", ppi = 72, scale = 1) } \arguments{ \item{input}{Shiny's input object.} @@ -38,6 +38,8 @@ column3: level (condition type)} \item{height}{Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive.} \item{ppi}{Pixel per inch. Defaults to 72 and supports reactive.} + +\item{scale}{Scale plot size. Defaults to 1, supports reactive.} } \value{ Reactive containing data.table used for plotting. From c62ab61a5eb68e580cdf7e3873478f03c8beffef Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 12:57:34 +0100 Subject: [PATCH 13/25] geneView_example: scale added --- exec/geneView_example.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exec/geneView_example.R b/exec/geneView_example.R index bddb915..4441db5 100644 --- a/exec/geneView_example.R +++ b/exec/geneView_example.R @@ -18,7 +18,8 @@ names(metadata)[1] <- "key" ui <- dashboardPage(header = dashboardHeader(), sidebar = dashboardSidebar( numericInput(inputId = "width", label = "width in cm", value = 0, min = 0), - numericInput(inputId = "height", label = "height in cm", value = 0, min = 0) + numericInput(inputId = "height", label = "height in cm", value = 0, min = 0), + sliderInput(inputId = "scale", label = "scale plot", value = 1, min = 1, max = 10) ), dashboardBody(fluidPage( geneViewUI("id") ))) @@ -34,7 +35,7 @@ server <- function(input, output) { metadata[level != "annotation"][["level"]] }) - gene <- callModule(geneView, "id", data = table.r, metadata.r, level.r, custom.label = table.r, plot.method = "static", width = reactive(input$width), height = reactive(input$height)) + gene <- callModule(geneView, "id", data = table.r, metadata.r, level.r, custom.label = table.r, plot.method = "static", width = reactive(input$width), height = reactive(input$height), scale = reactive(input$scale)) observe({ print(gene()) From fce6c61fd88e752ddeef4828ad79470f1ea8fa29 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 13:11:22 +0100 Subject: [PATCH 14/25] create_pca: added param scale --- R/function.R | 19 ++++++++++++------- man/create_pca.Rd | 5 ++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/R/function.R b/R/function.R index 4b5bd13..d63be2d 100644 --- a/R/function.R +++ b/R/function.R @@ -281,6 +281,7 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize #' @param width Set the width of the plot in cm (default = 28). #' @param height Set the height of the plot in cm (default = 28). #' @param ppi Pixel per inch (default = 72). +#' @param scale Modify plot size while preserving aspect ratio (Default = 1). #' #' @details If width and height are the same axis ratio will be set to one (quadratic plot). #' @details Width/ height limit = 500. If exceeded default to 500 and issue exceed_size = TRUE. @@ -288,7 +289,7 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize #' @import data.table #' #' @return A named list(plot = ggplot object, data = pca.data, width = width of plot (cm), height = height of plot (cm), ppi = pixel per inch, exceed_size = Boolean whether width/ height exceeded max). -create_pca <- function(data, dimensionA = 1, dimensionB = 2, dimensions = 6, on.columns = TRUE, labels = FALSE, custom.labels = NULL, pointsize = 2, labelsize = 3, width = 28, height = 28, ppi = 72) { +create_pca <- function(data, dimensionA = 1, dimensionB = 2, dimensions = 6, on.columns = TRUE, labels = FALSE, custom.labels = NULL, pointsize = 2, labelsize = 3, width = 28, height = 28, ppi = 72, scale = 1) { requireNamespace("FactoMineR", quietly = TRUE) requireNamespace("factoextra", quietly = TRUE) @@ -345,16 +346,16 @@ create_pca <- function(data, dimensionA = 1, dimensionB = 2, dimensions = 6, on. panel.background = ggplot2::element_blank(), axis.line.x = ggplot2::element_line(size=.3), axis.line.y = ggplot2::element_line(size=.3), - axis.title.x = ggplot2::element_text(color="black", size=11), - axis.title.y = ggplot2::element_text(color="black", size=11), + axis.title.x = ggplot2::element_text(color="black", size = 11 * scale), + axis.title.y = ggplot2::element_text(color="black", size = 11 * scale), #plot.title = element_text(color="black", size=12), plot.title = ggplot2::element_blank(), - legend.title= ggplot2::element_blank(), - text= ggplot2::element_text(size = 12) #size for all (legend?) labels + legend.title = ggplot2::element_blank(), + text = ggplot2::element_text(size = 12 * scale) #size for all (legend?) labels #legend.key = element_rect(fill="white") ) - pca_plot <- factoextra::fviz_pca_ind(pca, axes = c(dimensionA, dimensionB), invisible = "none", pointsize = pointsize, label = "none", axes.linetype = "blank", repel = FALSE) + pca_plot <- factoextra::fviz_pca_ind(pca, axes = c(dimensionA, dimensionB), invisible = "none", pointsize = pointsize * scale, label = "none", axes.linetype = "blank", repel = FALSE) pca_plot <- pca_plot + theme1 if(labels) { @@ -362,7 +363,7 @@ create_pca <- function(data, dimensionA = 1, dimensionB = 2, dimensions = 6, on. data = data.frame(pca$ind$coord), mapping = ggplot2::aes_(x = pca$ind$coord[, dimensionA], y = pca$ind$coord[, dimensionB], label = rownames(pca$ind$coord)), segment.color = "gray65", - size = labelsize, + size = labelsize * scale, force = 2, max.iter = 10000, point.padding = grid::unit(0.1, "lines") @@ -374,6 +375,10 @@ create_pca <- function(data, dimensionA = 1, dimensionB = 2, dimensions = 6, on. # pca_plot <- pca_plot + ggplot2::coord_fixed(ratio = 1) # } + # add scale factor + width <- width * scale + height <- height * scale + # size exceeded? exceed_size <- FALSE if(width > 500) { diff --git a/man/create_pca.Rd b/man/create_pca.Rd index 044613d..fbb0e70 100644 --- a/man/create_pca.Rd +++ b/man/create_pca.Rd @@ -6,7 +6,8 @@ \usage{ create_pca(data, dimensionA = 1, dimensionB = 2, dimensions = 6, on.columns = TRUE, labels = FALSE, custom.labels = NULL, - pointsize = 2, labelsize = 3, width = 28, height = 28, ppi = 72) + pointsize = 2, labelsize = 3, width = 28, height = 28, ppi = 72, + scale = 1) } \arguments{ \item{data}{data.table from which the plot is created (First column will be handled as rownames if not numeric).} @@ -32,6 +33,8 @@ create_pca(data, dimensionA = 1, dimensionB = 2, dimensions = 6, \item{height}{Set the height of the plot in cm (default = 28).} \item{ppi}{Pixel per inch (default = 72).} + +\item{scale}{Modify plot size while preserving aspect ratio (Default = 1).} } \value{ A named list(plot = ggplot object, data = pca.data, width = width of plot (cm), height = height of plot (cm), ppi = pixel per inch, exceed_size = Boolean whether width/ height exceeded max). From 6452b225c3025e154ff82a19676686caff8d937a Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 13:12:30 +0100 Subject: [PATCH 15/25] pca: added parameter scale --- R/pca.R | 10 +++++++--- man/pca.Rd | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/R/pca.R b/R/pca.R index b50a544..7b07791 100644 --- a/R/pca.R +++ b/R/pca.R @@ -77,6 +77,7 @@ pcaUI <- function(id, show.label = TRUE) { #' @param width Width of the plot in cm. Defaults to 28 and supports reactive. #' @param height Height of the plot in cm. Defaults to 28 and supports reactive. #' @param ppi Pixel per inch. Defaults to 72 and supports reactive. +#' @param scale Scale plot size. Defaults to 1, supports reactive. #' #' @details Width/ height/ ppi less or equal to zero will use default value. #' @@ -85,7 +86,7 @@ pcaUI <- function(id, show.label = TRUE) { #' @import data.table #' #' @export -pca <- function(input, output, session, data, types, levels = NULL, entryLabel = NULL, width = 28, height = 28, ppi = 72) { +pca <- function(input, output, session, data, types, levels = NULL, entryLabel = NULL, width = 28, height = 28, ppi = 72, scale = 1) { #handle reactive data data.r <- shiny::reactive({ if(shiny::is.reactive(data)){ @@ -124,6 +125,7 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = width <- ifelse(shiny::is.reactive(width), width(), width) height <- ifelse(shiny::is.reactive(height), height(), height) ppi <- ifelse(shiny::is.reactive(ppi), ppi(), ppi) + scale <- ifelse(shiny::is.reactive(scale), scale(), scale) if(!is.numeric(width) | width <= 0) { width <- 28 @@ -137,7 +139,8 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = list(width = width, height = height, - ppi = ppi) + ppi = ppi, + scale = scale) }) @@ -248,7 +251,8 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = on.columns = TRUE, width = size()$width, height = size()$height, - ppi = size()$ppi + ppi = size()$ppi, + scale = size()$scale ) progress$set(1) diff --git a/man/pca.Rd b/man/pca.Rd index c6f509e..eee0778 100644 --- a/man/pca.Rd +++ b/man/pca.Rd @@ -5,7 +5,7 @@ \title{pca module server logic} \usage{ pca(input, output, session, data, types, levels = NULL, entryLabel = NULL, - width = 28, height = 28, ppi = 72) + width = 28, height = 28, ppi = 72, scale = 1) } \arguments{ \item{input}{Shiny's input object} @@ -31,6 +31,8 @@ column4: sub_label (optional, added to id/ label)} \item{height}{Height of the plot in cm. Defaults to 28 and supports reactive.} \item{ppi}{Pixel per inch. Defaults to 72 and supports reactive.} + +\item{scale}{Scale plot size. Defaults to 1, supports reactive.} } \value{ A reactive containing list with dimensions. From e2bfbc965d770f8a04f0075d4080b85abe490502 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 13:13:38 +0100 Subject: [PATCH 16/25] pca_example: scale slider added --- exec/pca_example.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exec/pca_example.R b/exec/pca_example.R index 7cc78af..d7be244 100644 --- a/exec/pca_example.R +++ b/exec/pca_example.R @@ -14,13 +14,14 @@ names(metadata)[1] <- "key" ui <- dashboardPage(header = dashboardHeader(), sidebar = dashboardSidebar( numericInput(inputId = "width", label = "width in cm", value = 0, min = 0), - numericInput(inputId = "height", label = "height in cm", value = 0, min = 0) + numericInput(inputId = "height", label = "height in cm", value = 0, min = 0), + sliderInput(inputId = "scale", label = "scale plot", min = 1, max = 10, value = 1) ), dashboardBody(fluidPage( pcaUI("id") ))) server <- function(input, output) { - callModule(pca, "id", data = data, types = metadata, levels = metadata[level != "annotation"][["level"]], width = reactive(input$width), height = reactive(input$height)) + callModule(pca, "id", data = data, types = metadata, levels = metadata[level != "annotation"][["level"]], width = reactive(input$width), height = reactive(input$height), scale = reactive(input$scale)) } # Run the application From 912d8f22e1d28cc78a80579622d80ce412e04752 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 13:35:39 +0100 Subject: [PATCH 17/25] create_scatterplot: add param scale --- R/function.R | 42 ++++++++++++++++++++++----------------- man/create_scatterplot.Rd | 4 +++- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/R/function.R b/R/function.R index d63be2d..dc4dfa5 100644 --- a/R/function.R +++ b/R/function.R @@ -23,13 +23,14 @@ #' @param height Set plot height in cm (Default = "auto"). #' @param ppi Pixel per inch (default = 72). #' @param plot.method Whether the plot should be 'interactive' or 'static' (Default = 'static'). +#' @param scale Modify plot size while preserving aspect ratio (Default = 1). #' #' @details Width/ height limit = 500. If exceeded default to 500 and issue exceed_size = TRUE. #' #' @import data.table #' #' @return Returns list(plot = ggplotly/ ggplot, width, height, ppi, exceed_size). -create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize = 3, colors = NULL, x_label = "", y_label = "", z_label = "", density = T, line = T, categorized = F, highlight.data = NULL, highlight.labels = NULL, highlight.color = "#FF0000", xlim = NULL, ylim = NULL, colorbar.limits = NULL, width = "auto", height = "auto", ppi = 72, plot.method = "static"){ +create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize = 3, colors = NULL, x_label = "", y_label = "", z_label = "", density = T, line = T, categorized = F, highlight.data = NULL, highlight.labels = NULL, highlight.color = "#FF0000", xlim = NULL, ylim = NULL, colorbar.limits = NULL, width = "auto", height = "auto", ppi = 72, plot.method = "static", scale = 1){ ########## prepare data ########## #set labelnames if needed x_label <- ifelse(nchar(x_label), x_label, names(data)[2]) @@ -50,10 +51,10 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize if(ncol(data) >= 4){ z_head <- names(data)[4]} #delete rows where both 0 or at least one NA - rows.to.keep.data <- which(as.logical((data[,2] != 0) + (data[,3] != 0))) + rows.to.keep.data <- which(as.logical((data[, 2] != 0) + (data[, 3] != 0))) data <- data[rows.to.keep.data] if(!is.null(highlight.data)){ - rows.to.keep.high <- which(as.logical((highlight.data[,2] != 0) + (highlight.data[,3 != 0]))) + rows.to.keep.high <- which(as.logical((highlight.data[, 2] != 0) + (highlight.data[, 3 != 0]))) highlight.data <- highlight.data[rows.to.keep.high] } @@ -71,11 +72,12 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize panel.grid.minor = ggplot2::element_blank(), panel.border = ggplot2::element_blank(), panel.background = ggplot2::element_blank(), - axis.line.x = ggplot2::element_line(size=.3), - axis.line.y = ggplot2::element_line(size=.3), - axis.title.x = ggplot2::element_text(face="bold", color="black", size=10), - axis.title.y = ggplot2::element_text(face="bold", color="black", size=10), - plot.title = ggplot2::element_text(face="bold", color="black", size=12) + axis.line.x = ggplot2::element_line(size = .3), + axis.line.y = ggplot2::element_line(size = .3), + axis.title.x = ggplot2::element_text(face = "bold", color = "black", size = 10 * scale), + axis.title.y = ggplot2::element_text(face = "bold", color = "black", size = 10 * scale), + plot.title = ggplot2::element_text(face = "bold", color = "black", size = 12 * scale), + text = ggplot2::element_text(size = 10 * scale) # legend.background = element_rect(color = "red") #border color # legend.key = element_rect("green") #not working! ) @@ -148,7 +150,7 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize } #set points - plot <- plot + ggplot2::geom_point(size=pointsize, alpha=transparency, ggplot2::aes(text = hovertext)) + plot <- plot + ggplot2::geom_point(size = pointsize * scale, alpha = transparency, ggplot2::aes(text = hovertext)) if(!is.null(highlight.data)){ #set highlighted hovertext @@ -164,27 +166,27 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize } #set highlighted points - plot <- plot + ggplot2::geom_point(size = pointsize, alpha = transparency, inherit.aes = TRUE, data = highlight.data, color = highlight.color, show.legend = FALSE, ggplot2::aes(text = hovertext.high)) + plot <- plot + ggplot2::geom_point(size = pointsize * scale, alpha = transparency, inherit.aes = TRUE, data = highlight.data, color = highlight.color, show.legend = FALSE, ggplot2::aes(text = hovertext.high)) } # static points without hovertexts } else if(plot.method == "static") { seed <- Sys.getpid() + Sys.time() # set points - plot <- plot + ggplot2::geom_point(size = pointsize, alpha = transparency) + plot <- plot + ggplot2::geom_point(size = pointsize * scale, alpha = transparency) # set highlighted points if(!is.null(highlight.data)) { - plot <- plot + ggplot2::geom_point(size = pointsize, alpha = transparency, inherit.aes = TRUE, data = highlight.data, color = highlight.color, show.legend = FALSE) + plot <- plot + ggplot2::geom_point(size = pointsize * scale, alpha = transparency, inherit.aes = TRUE, data = highlight.data, color = highlight.color, show.legend = FALSE) # set repelling point labels if(!is.null(highlight.labels)) { - plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize, color = "black", segment.color = "gray65", force = 2, max.iter = 10000, point.padding = grid::unit(0.1, "lines"), label.size = NA, alpha = 0.5, seed = seed) - plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize, color = "black", segment.color = "gray65", force = 2, max.iter = 10000, point.padding = grid::unit(0.1, "lines"), label.size = NA, fill = NA, seed = seed) + plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize * scale, color = "black", segment.color = "gray65", force = 2, max.iter = 10000, point.padding = grid::unit(0.1, "lines"), label.size = NA, alpha = 0.5, seed = seed) + plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize * scale, color = "black", segment.color = "gray65", force = 2, max.iter = 10000, point.padding = grid::unit(0.1, "lines"), label.size = NA, fill = NA, seed = seed) } # set repelling labels (for only highlighted points shown) } else if(!is.null(highlight.labels) & length(highlight.labels) == nrow(data)) { - plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize, color = "black", segment.color = "gray65", force = 2, max.iter = 10000, point.padding = grid::unit(0.1, "lines"), label.size = NA, alpha = 0.5, seed = seed) - plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize, color = "black", segment.color = "gray65", force = 2, max.iter = 10000, point.padding = grid::unit(0.1, "lines"), label.size = NA, fill = NA, seed = seed) + plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize * scale, color = "black", segment.color = "gray65", force = 2, max.iter = 10000, point.padding = grid::unit(0.1, "lines"), label.size = NA, alpha = 0.5, seed = seed) + plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize * scale, color = "black", segment.color = "gray65", force = 2, max.iter = 10000, point.padding = grid::unit(0.1, "lines"), label.size = NA, fill = NA, seed = seed) } } @@ -234,6 +236,10 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize height <- height * (ppi / 2.54) } + # apply scale factor + width <- width * scale + height <- height * scale + # size exceeded? exceed_size <- FALSE limit <- 500 * (ppi / 2.54) @@ -252,9 +258,9 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize # add labels with arrows if(!is.null(highlight.labels)) { if(!is.null(highlight.data)) { - plot <- plotly::add_annotations(p = plot, x = highlight.data[[x_head]], y = highlight.data[[y_head]], text = highlight.labels, standoff = pointsize, font = list(size = labelsize), bgcolor = 'rgba(255, 255, 255, 0.5)') + plot <- plotly::add_annotations(p = plot, x = highlight.data[[x_head]], y = highlight.data[[y_head]], text = highlight.labels, standoff = pointsize * scale, font = list(size = labelsize * scale), bgcolor = 'rgba(255, 255, 255, 0.5)') } else if(nrow(data) == length(highlight.labels)) { - plot <- plotly::add_annotations(p = plot, x = data[[x_head]], y = data[[y_head]], text = highlight.labels, standoff = pointsize, font = list(size = labelsize), bgcolor = 'rgba(255, 255, 255, 0.5)') + plot <- plotly::add_annotations(p = plot, x = data[[x_head]], y = data[[y_head]], text = highlight.labels, standoff = pointsize * scale, font = list(size = labelsize * scale), bgcolor = 'rgba(255, 255, 255, 0.5)') } } } diff --git a/man/create_scatterplot.Rd b/man/create_scatterplot.Rd index 8c3985d..1eb26de 100644 --- a/man/create_scatterplot.Rd +++ b/man/create_scatterplot.Rd @@ -9,7 +9,7 @@ create_scatterplot(data, transparency = 1, pointsize = 1, labelsize = 3, density = T, line = T, categorized = F, highlight.data = NULL, highlight.labels = NULL, highlight.color = "#FF0000", xlim = NULL, ylim = NULL, colorbar.limits = NULL, width = "auto", height = "auto", - ppi = 72, plot.method = "static") + ppi = 72, plot.method = "static", scale = 1) } \arguments{ \item{data}{data.table containing plot data @@ -55,6 +55,8 @@ column 2, 3(, 4): x, y(, z)} \item{ppi}{Pixel per inch (default = 72).} \item{plot.method}{Whether the plot should be 'interactive' or 'static' (Default = 'static').} + +\item{scale}{Modify plot size while preserving aspect ratio (Default = 1).} } \value{ Returns list(plot = ggplotly/ ggplot, width, height, ppi, exceed_size). From 75110769ded7ed64943a9630089ca80efe76dba8 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 13:35:54 +0100 Subject: [PATCH 18/25] scatterPlot: scale param added --- R/scatterPlot.R | 10 +++++++--- man/scatterPlot.Rd | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/R/scatterPlot.R b/R/scatterPlot.R index 1fc2a8b..f79229b 100644 --- a/R/scatterPlot.R +++ b/R/scatterPlot.R @@ -122,13 +122,14 @@ scatterPlotUI <- function(id) { #' @param width Width of the plot in cm. Defaults to minimal size for readable labels and supports reactive. #' @param height Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive. #' @param ppi Pixel per inch. Defaults to 72 and supports reactive. +#' @param scale Scale plot size. Defaults to 1, supports reactive. #' #' @return Returns reactive containing data used for plot. #' #' @details Make sure to have the same columnnames in data and features. #' #' @export -scatterPlot <- function(input, output, session, data, types, features = NULL, markerReac = NULL, plot.method = "static", width = "auto", height = "auto", ppi = 72) { +scatterPlot <- function(input, output, session, data, types, features = NULL, markerReac = NULL, plot.method = "static", width = "auto", height = "auto", ppi = 72, scale = 1) { #handle reactive data data.r <- shiny::reactive({ if(shiny::is.reactive(data)){ @@ -154,6 +155,7 @@ scatterPlot <- function(input, output, session, data, types, features = NULL, ma width <- ifelse(shiny::is.reactive(width), width(), width) height <- ifelse(shiny::is.reactive(height), height(), height) ppi <- ifelse(shiny::is.reactive(ppi), ppi(), ppi) + scale <- ifelse(shiny::is.reactive(scale), scale(), scale) if(!is.numeric(width) || width <= 0) { width <- "auto" @@ -167,7 +169,8 @@ scatterPlot <- function(input, output, session, data, types, features = NULL, ma list(width = width, height = height, - ppi = ppi) + ppi = ppi, + scale = scale) }) #Fetch the reactive guide for this module @@ -333,7 +336,8 @@ scatterPlot <- function(input, output, session, data, types, features = NULL, ma plot.method = plot.method, width = size()$width, height = size()$height, - ppi = size()$ppi + ppi = size()$ppi, + scale = size()$scale ) progress$set(1) diff --git a/man/scatterPlot.Rd b/man/scatterPlot.Rd index c7e94e6..53dc5c2 100644 --- a/man/scatterPlot.Rd +++ b/man/scatterPlot.Rd @@ -6,7 +6,7 @@ \usage{ scatterPlot(input, output, session, data, types, features = NULL, markerReac = NULL, plot.method = "static", width = "auto", - height = "auto", ppi = 72) + height = "auto", ppi = 72, scale = 1) } \arguments{ \item{input}{Shiny's input object} @@ -34,6 +34,8 @@ column4: sub_label (optional, added to id/ label)} \item{height}{Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive.} \item{ppi}{Pixel per inch. Defaults to 72 and supports reactive.} + +\item{scale}{Scale plot size. Defaults to 1, supports reactive.} } \value{ Returns reactive containing data used for plot. From 5ae409a6f7fda74401c4a6c26f952756b99a4bbe Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 13:36:19 +0100 Subject: [PATCH 19/25] scatterPlot_example: scale slider added --- exec/scatterPlot_example.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exec/scatterPlot_example.R b/exec/scatterPlot_example.R index d65489c..2728010 100644 --- a/exec/scatterPlot_example.R +++ b/exec/scatterPlot_example.R @@ -20,7 +20,8 @@ ui <- dashboardPage(header = dashboardHeader(), sidebar = dashboardSidebar( markerUI("marker"), numericInput(inputId = "width", label = "width in cm", value = 0, min = 0), - numericInput(inputId = "height", label = "height in cm", value = 0, min = 0) + numericInput(inputId = "height", label = "height in cm", value = 0, min = 0), + sliderInput(inputId = "scale", label = "scale plot", min = 1, max = 10, value = 1) ), body = dashboardBody( fluidPage( @@ -32,7 +33,7 @@ ui <- dashboardPage(header = dashboardHeader(), server <- function(input, output) { marker <- callModule(marker, "marker", data) # highlight all manual cars - plot <- callModule(scatterPlot, "id", data = data, types = metadata[level != "annotation"], features = data[am == 1], markerReac = marker, plot.method = "static", width = reactive(input$width), height = reactive(input$height)) + plot <- callModule(scatterPlot, "id", data = data, types = metadata[level != "annotation"], features = data[am == 1], markerReac = marker, plot.method = "interactive", width = reactive(input$width), height = reactive(input$height), scale = reactive(input$scale)) observe({ print(plot()) From 35cf2c1138231163ce5f86c45d5e1674ed2cef8a Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 14:30:23 +0100 Subject: [PATCH 20/25] pca: clear plot on reset --- R/pca.R | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/R/pca.R b/R/pca.R index 7b07791..53de734 100644 --- a/R/pca.R +++ b/R/pca.R @@ -149,6 +149,9 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = rintrojs::introjs(session, options = list(steps = guide())) }) + # clear plot + clearPlot <- shiny::reactiveVal(value = FALSE) + #reset ui shiny::observeEvent(input$reset, { shinyjs::reset("label") @@ -157,6 +160,7 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = shinyjs::reset("pointsize") shinyjs::reset("labelsize") columnSelect <<- shiny::callModule(columnSelector, "select", type.columns = shiny::reactive(types.r()[level %in% levels.r(), c("key", "level"), with = FALSE]), columnTypeLabel = "Column types to choose from") + clearPlot(TRUE) }) columnSelect <- shiny::callModule(columnSelector, "select", type.columns = shiny::reactive(types.r()[level %in% levels.r(), c("key", "level"), with = FALSE]), columnTypeLabel = "Column types to choose from") @@ -233,6 +237,7 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = computed.data <- shiny::eventReactive(input$plot, { # enable downloadButton shinyjs::enable("download") + clearPlot(FALSE) #new progress indicator progress <- shiny::Progress$new() @@ -257,6 +262,9 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = progress$set(1) + # show plot + shinyjs::show("pca") + return(plot) }) @@ -276,7 +284,11 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = width = plot_width, height = plot_height, { - computed.data()$plot + if(clearPlot()){ + return() + } else { + computed.data()$plot + } }) #group data by dimension From b8bbba519a84581452308c63ead77f6374854643 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 14:38:19 +0100 Subject: [PATCH 21/25] geneView: clear plot on reset --- R/geneView.R | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/R/geneView.R b/R/geneView.R index 773c15a..251497d 100644 --- a/R/geneView.R +++ b/R/geneView.R @@ -161,6 +161,10 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot. rintrojs::introjs(session, options = list(steps = guide())) }) + # clear plot + clearPlot <- shiny::reactiveVal(FALSE) + + # reset shiny::observeEvent(input$reset, { shinyjs::reset("genes") shinyjs::reset("plotType") @@ -173,6 +177,7 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot. custom_label <<- shiny::callModule(label, "labeller", data = custom.label, sep = label.sep) } limiter <<- shiny::callModule(limit, "limit", lower = shiny::reactive(get_limits()[1]), upper = shiny::reactive(get_limits()[2])) + clearPlot(TRUE) }) get_limits <- shiny::reactive({ @@ -255,6 +260,7 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot. plot <- shiny::eventReactive(input$plot, { # enable downloadButton shinyjs::enable("download") + clearPlot(FALSE) #new progress indicator progress <- shiny::Progress$new() @@ -328,30 +334,38 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot. if(plot.method == "interactive") { output$interactive <- plotly::renderPlotly({ - #progress indicator - progress <- shiny::Progress$new() - on.exit(progress$close()) - progress$set(message = "Rendering plot", value = 0) - - plot <- plot()$plot - - progress$set(value = 1) - return(plot) - }) - } else if(plot.method == "static") { - output$static <- shiny::renderPlot( - width = shiny::reactive(plot()$width * (plot()$ppi / 2.54)), - height = shiny::reactive(plot()$height * (plot()$ppi / 2.54)), - { + if(clearPlot()) { + return() + } else { #progress indicator progress <- shiny::Progress$new() on.exit(progress$close()) - progress$set(message = "Rendering plot", value = 0.3) + progress$set(message = "Rendering plot", value = 0) plot <- plot()$plot progress$set(value = 1) return(plot) + } + }) + } else if(plot.method == "static") { + output$static <- shiny::renderPlot( + width = shiny::reactive(plot()$width * (plot()$ppi / 2.54)), + height = shiny::reactive(plot()$height * (plot()$ppi / 2.54)), + { + if(clearPlot()) { + return() + } else { + #progress indicator + progress <- shiny::Progress$new() + on.exit(progress$close()) + progress$set(message = "Rendering plot", value = 0.3) + + plot <- plot()$plot + + progress$set(value = 1) + return(plot) + } }) } From 4d8fe8beb43b3614c74078034e773899041b4c34 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 14:43:07 +0100 Subject: [PATCH 22/25] limit: fixed bug where ui wasn't reset --- R/limit.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/limit.R b/R/limit.R index 9b3e436..e7499f7 100644 --- a/R/limit.R +++ b/R/limit.R @@ -28,6 +28,11 @@ limitUI <- function(id, label = "Limit"){ #' #' @export limit <- function(input, output, session, lower = NULL, upper = NULL){ + # reset on re-run + shinyjs::reset("enable") + shinyjs::reset("lowerLimit") + shinyjs::reset("upperLimit") + # evaluate reactive parameter lower.r <- shiny::reactive({ if(shiny::is.reactive(lower)) { From 9f71cb83d8e2bd1491fef51fe8a9de8246de3dca Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 15:12:12 +0100 Subject: [PATCH 23/25] scatterPlot: hide plot on reset; fixed limit reset bug --- R/scatterPlot.R | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/R/scatterPlot.R b/R/scatterPlot.R index f79229b..71b0f59 100644 --- a/R/scatterPlot.R +++ b/R/scatterPlot.R @@ -182,6 +182,9 @@ scatterPlot <- function(input, output, session, data, types, features = NULL, ma data_x <- shiny::reactive(as.matrix(data.r()[, xaxis$selectedColumn(), with = FALSE])) data_y <- shiny::reactive(as.matrix(data.r()[, yaxis$selectedColumn(), with = FALSE])) + # clear plot + clearPlot <- shiny::reactiveVal(FALSE) + #reset ui shiny::observeEvent(input$reset, { shinyjs::reset("density") @@ -194,8 +197,9 @@ scatterPlot <- function(input, output, session, data, types, features = NULL, ma colorPicker <<- shiny::callModule(colorPicker2, "color", distribution = list("sequential", "diverging"), winsorize = winsorize) transform_x <<- shiny::callModule(transformation, "transform_x", data = data_x) transform_y <<- shiny::callModule(transformation, "transform_y", data = data_y) - limit_x <<- shiny::callModule(limit, "xaxis_limit", lower = shiny::reactive(get_x_limit()[1]), upper = shiny::reactive(get_x_limit()[2])) - limit_y <<- shiny::callModule(limit, "yaxis_limit", lower = shiny::reactive(get_y_limit()[1]), upper = shiny::reactive(get_y_limit()[2])) + limit_x <<- shiny::callModule(limit, "xaxis_limit", lower = shiny::reactive(result.data()$xlim[1]), upper = shiny::reactive(result.data()$xlim[2])) + limit_y <<- shiny::callModule(limit, "yaxis_limit", lower = shiny::reactive(result.data()$ylim[1]), upper = shiny::reactive(result.data()$ylim[2])) + clearPlot(TRUE) }) winsorize <- shiny::reactive({ @@ -297,6 +301,7 @@ scatterPlot <- function(input, output, session, data, types, features = NULL, ma plot <- shiny::eventReactive(input$plot, { #enable downloadbutton shinyjs::enable("download") + clearPlot(FALSE) #new progress indicator progress <- shiny::Progress$new() @@ -362,22 +367,29 @@ scatterPlot <- function(input, output, session, data, types, features = NULL, ma width = shiny::reactive(plot()$width * (plot()$ppi / 2.54)), height = shiny::reactive(plot()$height * (plot()$ppi / 2.54)), { - plot()$plot + if(clearPlot()) { + return() + } else { + plot()$plot + } } ) } else if(plot.method == "interactive") { output$interactive <- plotly::renderPlotly({ - #new progress indicator - progress <- shiny::Progress$new() - on.exit(progress$close()) - progress$set(0.2, message = "Render plot") - - plot <- plot()$plot - - progress$set(1) - return(plot) + if(clearPlot()) { + return() + } else { + #new progress indicator + progress <- shiny::Progress$new() + on.exit(progress$close()) + progress$set(0.2, message = "Render plot") + + plot <- plot()$plot + + progress$set(1) + return(plot) + } }) - } output$download <- shiny::downloadHandler(filename = "scatterPlot.zip", From 3a81ef2a5e946faa35c761b4cf2d907c84e33e45 Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 15:24:45 +0100 Subject: [PATCH 24/25] heatmap: clear plot on reset --- R/heatmap.R | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/R/heatmap.R b/R/heatmap.R index a6a7e2c..df9c9ec 100644 --- a/R/heatmap.R +++ b/R/heatmap.R @@ -208,7 +208,10 @@ heatmap <- function(input, output, session, data, types, plot.method = "static", } }) - #reset ui + # clear plot + clearPlot <- shiny::reactiveVal(FALSE) + + # reset ui shiny::observeEvent(input$reset, { shinyjs::reset("cluster.distance") shinyjs::reset("cluster.method") @@ -223,6 +226,7 @@ heatmap <- function(input, output, session, data, types, plot.method = "static", if(!is.null(custom.row.label)) { custom_label <<- shiny::callModule(label, "labeller", data = custom.row.label, label = "Select row label", sep = label.sep, disable = shiny::reactive(!input$row.label)) } + clearPlot(TRUE) }) columns <- shiny::callModule(columnSelector, "select", type.columns = types, columnTypeLabel = "Column types to choose from") @@ -252,6 +256,7 @@ heatmap <- function(input, output, session, data, types, plot.method = "static", plot <- shiny::eventReactive(input$plot, { # enable downloadButton shinyjs::enable("download") + clearPlot(FALSE) #new progress indicator progress <- shiny::Progress$new() @@ -296,16 +301,20 @@ heatmap <- function(input, output, session, data, types, plot.method = "static", }) output$interactive <- plotly::renderPlotly({ - #new progress indicator - progress <- shiny::Progress$new() - on.exit(progress$close()) - progress$set(0.2, message = "Render plot") + if(clearPlot()) { + return() + } else { + #new progress indicator + progress <- shiny::Progress$new() + on.exit(progress$close()) + progress$set(0.2, message = "Render plot") - plot <- plot()$plot + plot <- plot()$plot - progress$set(1) + progress$set(1) - return(plot) + return(plot) + } }) }else{ output$heatmap <- shiny::renderUI({ @@ -316,15 +325,19 @@ heatmap <- function(input, output, session, data, types, plot.method = "static", width = shiny::reactive(plot()$width * (plot()$ppi / 2.54)), height = shiny::reactive(plot()$height * (plot()$ppi / 2.54)), { - #new progress indicator - progress <- shiny::Progress$new() - on.exit(progress$close()) - progress$set(0.2, message = "Render plot") + if(clearPlot()) { + return() + } else { + #new progress indicator + progress <- shiny::Progress$new() + on.exit(progress$close()) + progress$set(0.2, message = "Render plot") - plot <- plot()$plot + plot <- plot()$plot - progress$set(1) - return(ComplexHeatmap::draw(plot, heatmap_legend_side = "bottom")) + progress$set(1) + return(ComplexHeatmap::draw(plot, heatmap_legend_side = "bottom")) + } }) } From c8da6c4be7e73a252530e25f7fdbc17e7c9b510b Mon Sep 17 00:00:00 2001 From: Schultheis Date: Fri, 12 Jan 2018 15:29:52 +0100 Subject: [PATCH 25/25] global_cor_heatmap: clear plot on reset --- R/global_cor_heatmap.R | 48 +++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/R/global_cor_heatmap.R b/R/global_cor_heatmap.R index 8aada9a..4ffd71b 100644 --- a/R/global_cor_heatmap.R +++ b/R/global_cor_heatmap.R @@ -220,6 +220,9 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method } # functionality ----------------------------------------------------------- + # clear plot + clearPlot <- shiny::reactiveVal(FALSE) + # reset ui shiny::observeEvent(input$reset, { shinyjs::reset("calc") @@ -233,6 +236,7 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method columns <<- shiny::callModule(columnSelector, "select", type.columns = types, columnTypeLabel = "Column types to choose from") transform <<- shiny::callModule(transformation, "transform", data = shiny::reactive(as.matrix(data_r()[, columns$selectedColumns(), with = FALSE]))) colorPicker <<- shiny::callModule(colorPicker2, "color", distribution = shiny::reactive(tolower(input$distribution)), winsorize = shiny::reactive(equalize(result_data()[, -1]))) + clearPlot(TRUE) }) # warning if plot size exceeds limits @@ -311,6 +315,8 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method plot <- shiny::eventReactive(input$plot, { # enable downloadButton shinyjs::enable("download") + # show plot + clearPlot(FALSE) # progress indicator progress <- shiny::Progress$new() @@ -365,34 +371,42 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method width = shiny::reactive(plot()$width * (plot()$ppi / 2.54)), height = shiny::reactive(plot()$height * (plot()$ppi / 2.54)), { + if(clearPlot()) { + return() + } else { + # progress indicator + progress <- shiny::Progress$new() + on.exit(progress$close()) + progress$set(0.2, message = "Rendering plot") + + # get plot + plot <- plot()$plot + + # update progress indicator + progress$set(1) + + # draw plot + return(ComplexHeatmap::draw(plot, heatmap_legend_side = "bottom")) + } + } + ) + }else if(plot.method == "interactive") { + output$interactive <- plotly::renderPlotly({ + if(clearPlot()) { + return() + } else { # progress indicator progress <- shiny::Progress$new() on.exit(progress$close()) progress$set(0.2, message = "Rendering plot") - # get plot plot <- plot()$plot # update progress indicator progress$set(1) - # draw plot - return(ComplexHeatmap::draw(plot, heatmap_legend_side = "bottom")) + return(plot) } - ) - }else if(plot.method == "interactive") { - output$interactive <- plotly::renderPlotly({ - # progress indicator - progress <- shiny::Progress$new() - on.exit(progress$close()) - progress$set(0.2, message = "Rendering plot") - - plot <- plot()$plot - - # update progress indicator - progress$set(1) - - return(plot) }) }