Commit 525353a2 authored by Etienne Rifa's avatar Etienne Rifa
Browse files

v1.2.0

boxplot: add button to plot all conditions (even with no values) or not
parent 4929ab25
Package: graphstatsr
Title: graphstatsr
Version: 1.1.0
Version: 1.2.0
Authors@R:
person(given = "Etienne",
family = "Rifa",
......
......@@ -178,6 +178,7 @@ mod_Inputs_ui <- function(id){
label = "Select number of plot per pdf page (max 4 per page):",
choices = c(1:4), selected = 1
),
materialSwitch(ns("plotall"), label = "Plot all conditions (even NAs)", value = TRUE, status = "primary"),
actionButton(ns("go4"), "Just plot", icon = icon("play-circle"), style="color: #fff; background-color: #3b9ef5; border-color: #1a4469"),
actionButton(ns("go3"), "Run plot/stats & tests", icon = icon("play-circle"), style="color: #fff; background-color: #3b9ef5; border-color: #1a4469"),
downloadButton(outputId = ns("boxplots_download"), label = "Download all plots (long process)")
......@@ -254,7 +255,7 @@ mod_Inputs_server <- function(id, r = r, session = session){
# Preview
output$prevds1 <- renderPrint({
cat(file = stderr(), 'rendering ds1', "\n")
cat('Running graphstatsr v1.1.0\n')
cat('Running graphstatsr v1.2.0\n')
cat(glue::glue("Features table with {nrow(dataset1())} rows and {ncol(dataset1())} columns.\n\n"))
head(dataset1()[, 1:6])
if (is.null(dataset1())) {
......@@ -718,27 +719,27 @@ mod_Inputs_server <- function(id, r = r, session = session){
ytitle <- glue::glue("{ytitle}, norm.: {r_values$norm1}")
}
is_outlier <- function(x) {
return(x < quantile(x, 0.25) - 1.5 * IQR(x) | x > quantile(x, 0.75) + 1.5 * IQR(x))
}
fun <- glue::glue('tabfeat = tabF_melt2[tabF_melt2$features == input$feat1,] %>% filter(!is.na(value)) %>%
fun <- glue::glue('tabfeat = tabF_melt2[tabF_melt2$features == input$feat1,] %>%
group_by({fact3ok}) %>%
mutate(outlier=ifelse(is_outlier(value), sample.id, NA))')
mutate(outlier=ifelse(is_outlier(value), as.character(sample.id), NA))')
eval(parse(text=fun))
if(!input$plotall){
tabfeat <- tabfeat %>% filter(!is.na(value))
}
fun <- glue::glue('p <- ggplot(tabfeat, aes(x = {fact3ok}, y = value)) +
geom_boxplot(fill = "#99AFE3") + theme_bw() + xlab("Condition") + ylab(ytitle) + ggtitle(input$feat1) +
theme(legend.position = "None", axis.text.x = element_text(angle = 45, hjust=1))')
eval(parse(text=fun))
# Hoverinfo
tabfeat$sample.id <- as.character(tabfeat$sample.id)
ggly <- ggplotly(p)
hoverinfo <- with(tabfeat, paste0("sample: ", sample.id, "</br></br>",
"value: ", value))
ggly$x$data[[1]]$text <- hoverinfo
ggly$x$data[[1]]$hoverinfo <- c("text", "boxes")
# # Hoverinfo BUG
# tabfeat$sample.id <- as.character(tabfeat$sample.id)
# hoverinfo <- with(tabfeat, paste0("sample: ", sample.id, "</br></br>",
# "value: ", value))
# ggly$x$data[[1]]$text <- hoverinfo
# ggly$x$data[[1]]$hoverinfo <- c("text", "boxes")
cat(file=stderr(), 'BOXPLOT done', "\n")
......@@ -777,10 +778,6 @@ mod_Inputs_server <- function(id, r = r, session = session){
listP <- list()
FEAT = levels(tabF_melt2$features)
print(head(FEAT))
is_outlier <- function(x) {
return(x < quantile(x, 0.25) - 1.5 * IQR(x) | x > quantile(x, 0.75) + 1.5 * IQR(x))
}
for(i in 1:length(FEAT)){
......@@ -795,10 +792,15 @@ mod_Inputs_server <- function(id, r = r, session = session){
ytitle <- glue::glue("{ytitle}, norm.: {r_values$norm1}")
}
fun <- glue::glue('tabfeat = tabF_melt2[tabF_melt2$features == FEAT[i],] %>% filter(!is.na(value)) %>%
fun <- glue::glue('tabfeat = tabF_melt2[tabF_melt2$features == FEAT[i],] %>%
group_by({fact3ok}) %>%
mutate(outlier=ifelse(is_outlier(value), sample.id, NA))')
eval(parse(text=fun))
if(!input$plotall){
tabfeat <- tabfeat %>% filter(!is.na(value))
}
if(nrow(tabfeat) == 0){print("no data"); next}
fun <- glue::glue('listP[[FEAT[i]]] <- ggplot(tabfeat, aes(x = {fact3ok}, y = value)) +
......
......@@ -22,3 +22,11 @@ prev <- function(x){
x[1:nr,1:nc]
}
#' Detect outlier from numeric vector
#' @param x a vector
#'
is_outlier <- function(x) {
vec0 = x < quantile(x, 0.25, na.rm = TRUE) - 1.5 * IQR(x, na.rm = TRUE) | x > quantile(x, 0.75, na.rm = TRUE) + 1.5 * IQR(x, na.rm = TRUE)
vec0[is.na(vec0)] <- FALSE
return(vec0)
}
\ No newline at end of file
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{is_outlier}
\alias{is_outlier}
\title{Detect outlier from numeric vector}
\usage{
is_outlier(x)
}
\arguments{
\item{x}{a vector}
}
\description{
Detect outlier from numeric vector
}
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