Commit 86e4defc authored by arsenij.ustjanzew's avatar arsenij.ustjanzew
Browse files

Changed the manpage description.

Small changes in the strings.
Deleted unused text.
parent 03afcbee
#' Renders a Sequence saturation plot
#' Renders a scatter plot
#'
#' @param object A \linkS4class{i2dash::i2dashboard} object.
#' @param x Numeric values mapped to the x-axis. In case of a nested list, a dropdown menu will be provided in the interactive mode.
#' @param y Numeric values mapped to the y-axis. In case of a nested list, a dropdown menu will be provided in the interactive mode.
#' @param colour_by A factor that will be mapped to colours. In case of a nested list, a dropdown menu will be provided in the interactive mode.
#' @param labels A list with sample names It should be of the same length as x and y. A dropdown menu for colouring by label will be provided.
#' @param title A title that will be displayed on top.
#' @param x A vector with numerical values or a named list will be mapped to the x-axis. In case of a named list, a dropdown menu will be provided in the interactive mode. Note: The length of vectors x and y should be the same as well as the length of all vectors in case of a named list.
#' @param y A vector with numerical values or a named list will be mapped to the y-axis. In case of a named list, a dropdown menu will be provided in the interactive mode. Note: The length of vectors x and y should be the same as well as the length of all vectors in case of a named list.
#' @param colour_by (Optional) A vector with factorial values or a named list will be used for colouring. In case of a named list, a dropdown menu will be provided in the interactive mode. Note: The length of the vector should be of the same length as x and y as well as the length of all vectors in case of a named list.
#' @param labels (Optional) A vector or list with sample names (numeric or characters). A dropdown menu for colouring by label will be provided. Note: The length of the vector should be of the same length as x and y.
#' @param title (Optional) The title of the components junk.
#'
#' @return A string containing markdown code for the rendered textbox
scatterplot <- function(object, x, y, colour_by = NULL, labels = NULL, title = NULL) {
......@@ -25,18 +25,18 @@ scatterplot <- function(object, x, y, colour_by = NULL, labels = NULL, title = N
if(is.null(names(labels)) & !is.null(labels)) labels %<>% magrittr::set_names("labels")
# Validate input
if(!all(sapply(x, is.numeric))) stop("x should only contain numeric values.")
if(!all(sapply(y, is.numeric))) stop("y should only contain numeric values.")
if(!all(sapply(x, is.numeric))) stop("x should only contain numerical values.")
if(!all(sapply(y, is.numeric))) stop("y should only contain numerical values.")
# Check, if lengths in a list are the same and if x and y and label and color_by are the same length
if(length(unique(sapply(x, length))) != 1) stop("list x should contain elements with the same length.")
if(length(unique(sapply(y, length))) != 1) stop("list y should contain elements with the same length.")
if(length(unique(sapply(colour_by, length))) != 1 & !is.null(colour_by)) stop("list colour_by should contain elements with the same length.")
if(length(unique(sapply(labels, length))) != 1 & !is.null(labels)) stop("list labels should contain elements with the same length.")
if(length(unique(sapply(x, length))) != 1) stop("The list x should contain elements with the same length.")
if(length(unique(sapply(y, length))) != 1) stop("The list y should contain elements with the same length.")
if(length(unique(sapply(colour_by, length))) != 1 & !is.null(colour_by)) stop("The list colour_by should contain elements with the same length.")
if(length(unique(sapply(labels, length))) != 1 & !is.null(labels)) stop("The list labels should contain elements with the same length.")
if(!identical(length(x[[1]]), length(y[[1]]))) stop("all arguments should be of the the same length.")
if(!identical(length(x[[1]]), length(colour_by[[1]])) & !is.null(colour_by)) stop("all arguments should be of the the same length.")
if(!identical(length(x[[1]]), length(labels[[1]])) & !is.null(labels)) stop("all arguments should be of the the same length.")
if(!identical(length(x[[1]]), length(y[[1]]))) stop("All arguments should be of the the same length.")
if(!identical(length(x[[1]]), length(colour_by[[1]])) & !is.null(colour_by)) stop("All arguments should be of the the same length.")
if(!identical(length(x[[1]]), length(labels[[1]])) & !is.null(labels)) stop("All arguments should be of the the same length.")
# Create component environment
env <- new.env()
......@@ -51,7 +51,7 @@ scatterplot <- function(object, x, y, colour_by = NULL, labels = NULL, title = N
env$labels <- labels
# save environment object
# Save environment object
saveRDS(env, file = file.path(object@workdir, "envs", paste0(env_id, ".rds")))
# Expand component
......@@ -59,67 +59,3 @@ scatterplot <- function(object, x, y, colour_by = NULL, labels = NULL, title = N
expanded_component <- knitr::knit_expand(file = system.file("templates", "scatterplot.Rmd", package = "i2dash.scrnaseq"), title = title, env_id = env_id, date = timestamp)
return(expanded_component)
}
# # validate input, create environment variables, save environment object
# .validate_input_sequence_saturation(object@workdir, env_id, x, y, colour_by, labels)
#
# timestamp <- Sys.time()
# expanded_component <- knitr::knit_expand(file = system.file("templates", "sequence_saturation_template.Rmd", package = "i2dash.scrnaseq"), title = title, env_id = env_id, date = timestamp)
# return(expanded_component)
# }
#
# .validate_input_sequence_saturation <- function(workdir, env_id, x, y, colour_by, labels) {
# env <- new.env()
# env$x_selection <- FALSE
# env$y_selection <- FALSE
# env$colour_by_selection <- FALSE
#
# # Create lists if needed
# if(!is.list(x)) x <- list(x)
# if(!is.list(y)) y <- list(y)
# if(!is.list(colour_by) & !is.null(colour_by)) colour_by <- list(colour_by)
# if(!is.list(labels) & !is.null(labels)) labels <- list(labels)
#
# # should I use magrittr::%<>% ?
# # name the lists
# library(magrittr)
# if(is.null(names(x))) x %<>% magrittr::set_names("x")
# if(is.null(names(y))) y %<>% magrittr::set_names("y")
# if(is.null(names(colour_by)) & !is.null(colour_by)) colour_by %<>% magrittr::set_names("colour")
# if(is.null(names(labels)) & !is.null(labels)) labels %<>% magrittr::set_names("labels")
#
# # Check existence of x and y
# if(is.null(x)) stop("x is required.")
# if(is.null(y)) stop("y is required.")
#
# # Check validity
# if(!all(sapply(x, is.numeric))) stop("x should only contain numeric values.")
# if(!all(sapply(y, is.numeric))) stop("y should only contain numeric values.")
#
# # Check if lengths in a list are the same and if x and y and label and color_by are the same length
# if(length(unique(sapply(x, length))) != 1) stop("list x should contain elements with the same length.")
# if(length(unique(sapply(y, length))) != 1) stop("list y should contain elements with the same length.")
# if(length(unique(sapply(colour_by, length))) != 1 & !is.null(colour_by)) stop("list colour_by should contain elements with the same length.")
# if(length(unique(sapply(labels, length))) != 1 & !is.null(labels)) stop("list labels should contain elements with the same length.")
#
# if(!identical(length(x[[1]]), length(y[[1]]))) stop("all arguments should be of the the same length.")
# if(!identical(length(x[[1]]), length(colour_by[[1]])) & !is.null(colour_by)) stop("all arguments should be of the the same length.")
# if(!identical(length(x[[1]]), length(labels[[1]])) & !is.null(labels)) stop("all arguments should be of the the same length.")
#
# # Add objects to env
# env$x <- x
# env$x_selection <- length(env$x) > 1
#
# env$y <- y
# env$y_selection <- length(env$y) > 1
#
# env$colour_by <- colour_by
# env$colour_by_selection <- length(env$colour_by) > 1
#
# env$labels <- labels
#
# # save environment as rds-object
# saveRDS(env, file = file.path(workdir, "envs", paste0(env_id, ".rds")))
# print("validation TRUE")
# }
#' Renders a scatter plot
#'
#' @param labels A list with sample names, that should be of the same length as x and y.
#' @param x Numeric values mapped to the x-axis. In case of a nested list, a dropdown menu will be provided in the interactive mode.
#' @param y Numeric values mapped to the y-axis. In case of a nested list, a dropdown menu will be provided in the interactive mode.
#' @param colour_by A factor that will be mapped to colours. In case of a nested list, a dropdown menu will be provided in the interactive mode.
#' @param df A dataframe containing the data for the boxplot
#' @param labels A list with sample names, which should be of the same length as x and y.
#' @param colour_by A list containing factorial values that will be used for colouring. In case of a named list, a dropdown menu will be provided in the interactive mode. Note: The length of all vectors in case of a named list should be of the same length as x and y.
#' @param checkbox A boolean value as indicator for colouring by labels.
#' @param selected_label The label (character) selected by the user.
#'
#' @return A list with 1. the plotly object & 2. the data frame used in the plot
#' @return An object of class \code{plotly}.
#' @export
plotly_scatterplot <- function(df, labels = NULL, colour_by = NULL, checkbox = FALSE, selected_label = NULL){
# create data.frame for plot (fill colour_by & labels with dummy data if NULL)
# dummy_values <- FALSE
# plot_list <- list()
# if (!is.null(labels)) plot_list <- rlist::list.append(plot_list, labels) else plot_list <- rlist::list.append(plot_list, c(1:length(x[[1]])))
# plot_list <- rlist::list.append(plot_list, c(x, y))
# if (!is.null(colour_by)) {
# plot_list <- rlist::list.append(plot_list, colour_by)
# } else {
# plot_list <- rlist::list.append(plot_list, c(1:length(x[[1]])))
# dummy_values <- TRUE
# }
# plot_df <- do.call("data.frame", plot_list)
# assign variables
if(!is.null(labels)) labels <- df[[1]]
x_value <- df[[2]]
y_value <- df[[3]]
if(!is.null(colour_by)) colour_by <- df[[4]]
x_title <- names(df[2])
y_title <- names(df[3])
# if(dummy_values) {
# colour_by <- NULL
# }
# if(is.null(labels)) {
# labels <- NULL
# }
if(is.null(checkbox)) {
checkbox <- FALSE
}
......@@ -61,26 +42,6 @@ plotly_scatterplot <- function(df, labels = NULL, colour_by = NULL, checkbox = F
)
}
# if (!is.null(labels)) {
# if (checkbox) {
# colour_by <- NULL
# point_index <- match(selected_label, plot_df[[1]])
# point <- plot_df[point_index,]
# a <- list(
# x = point[,2],
# y = point[,3],
# text = point[,1],
# xref = "x",
# yref = "y",
# showarrow = T,
# arrowhead = 7,
# arrowcolor = "red",
# ax = 20,
# ay = -40
# )
# }
# }
# plotly
plotly::plot_ly(df, x = x_value, y = y_value, color = colour_by, text = labels) %>%
plotly::add_markers() %>%
......
......@@ -62,7 +62,7 @@ if (!is.null({{ env_id }}$labels)) {
))
}
# download_link
# Download link
ui_list <- rlist::list.append(ui_list, tags$div(tags$br(), downloadButton('downloadData_{{ env_id }}', 'Download data')))
#
......
......@@ -8,16 +8,18 @@ plotly_scatterplot(df, labels = NULL, colour_by = NULL,
checkbox = FALSE, selected_label = NULL)
}
\arguments{
\item{labels}{A list with sample names, that should be of the same length as x and y.}
\item{df}{A dataframe containing the data for the boxplot}
\item{colour_by}{A factor that will be mapped to colours. In case of a nested list, a dropdown menu will be provided in the interactive mode.}
\item{labels}{A list with sample names, which should be of the same length as x and y.}
\item{x}{Numeric values mapped to the x-axis. In case of a nested list, a dropdown menu will be provided in the interactive mode.}
\item{colour_by}{A list containing factorial values that will be used for colouring. In case of a named list, a dropdown menu will be provided in the interactive mode. Note: The length of all vectors in case of a named list should be of the same length as x and y.}
\item{y}{Numeric values mapped to the y-axis. In case of a nested list, a dropdown menu will be provided in the interactive mode.}
\item{checkbox}{A boolean value as indicator for colouring by labels.}
\item{selected_label}{The label (character) selected by the user.}
}
\value{
A list with 1. the plotly object & 2. the data frame used in the plot
An object of class \code{plotly}.
}
\description{
Renders a scatter plot
......
......@@ -2,7 +2,7 @@
% Please edit documentation in R/scatterplot.R
\name{scatterplot}
\alias{scatterplot}
\title{Renders a Sequence saturation plot}
\title{Renders a scatter plot}
\usage{
scatterplot(object, x, y, colour_by = NULL, labels = NULL,
title = NULL)
......@@ -10,19 +10,19 @@ scatterplot(object, x, y, colour_by = NULL, labels = NULL,
\arguments{
\item{object}{A \linkS4class{i2dash::i2dashboard} object.}
\item{x}{Numeric values mapped to the x-axis. In case of a nested list, a dropdown menu will be provided in the interactive mode.}
\item{x}{A vector with numerical values or a named list will be mapped to the x-axis. In case of a named list, a dropdown menu will be provided in the interactive mode. Note: The length of vectors x and y should be the same as well as the length of all vectors in case of a named list.}
\item{y}{Numeric values mapped to the y-axis. In case of a nested list, a dropdown menu will be provided in the interactive mode.}
\item{y}{A vector with numerical values or a named list will be mapped to the y-axis. In case of a named list, a dropdown menu will be provided in the interactive mode. Note: The length of vectors x and y should be the same as well as the length of all vectors in case of a named list.}
\item{colour_by}{A factor that will be mapped to colours. In case of a nested list, a dropdown menu will be provided in the interactive mode.}
\item{colour_by}{(Optional) A vector with factorial values or a named list will be used for colouring. In case of a named list, a dropdown menu will be provided in the interactive mode. Note: The length of the vector should be of the same length as x and y as well as the length of all vectors in case of a named list.}
\item{labels}{A list with sample names It should be of the same length as x and y. A dropdown menu for colouring by label will be provided.}
\item{labels}{(Optional) A vector or list with sample names (numeric or characters). A dropdown menu for colouring by label will be provided. Note: The length of the vector should be of the same length as x and y.}
\item{title}{A title that will be displayed on top.}
\item{title}{(Optional) The title of the components junk.}
}
\value{
A string containing markdown code for the rendered textbox
}
\description{
Renders a Sequence saturation plot
Renders a scatter plot
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment