Skip to content

Commit

Permalink
add possibility to order boxplot X axis by mean or not
Browse files Browse the repository at this point in the history
  • Loading branch information
aucomte committed Mar 19, 2020
1 parent 16ec580 commit 5b55239
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
16 changes: 14 additions & 2 deletions inst/app/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,21 @@ GraphTime <- function(tab,tim,var1,var2,var3,var4,timeselecter, smoothing){
#---------------------------------------
#visu

NiceGraph <- function(tab,var1,var2,var3,var4){
NiceGraph <- function(tab,var1,var2,var3,var4, order){
tab = as.data.frame(tab)
p <- ggplot(data=tab, aes(x=reorder(tab[,var2], as.numeric(as.character(tab[,var1])),FUN = median), y=as.numeric(as.character(tab[,var1])))) + geom_boxplot()
if (order == TRUE){
p <- ggplot(data=tab, aes(x=reorder(tab[,var2], as.numeric(as.character(tab[,var1])),FUN = median), y=as.numeric(as.character(tab[,var1])))) + geom_boxplot()
}
else{
listX = vector()
for (i in 1:nrow(tab)){
if (!(as.character(tab[i,var2]) %in% listX)){
listX[length(listX)+1] = as.character(tab[i,var2])
}
}
tab[,var2] = factor(tab[,var2], levels = listX)
p <- ggplot(data=tab, aes(x=tab[,var2], y=as.numeric(as.character(tab[,var1])))) + geom_boxplot()
}
if(var3 != "None" && !is.null(var3) && var3 !=""){
p <- p + geom_jitter(aes(colour=tab[,var3]),width = 0.2)
}
Expand Down
10 changes: 7 additions & 3 deletions inst/app/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ server <-function(input,output,session){
factorPG1 = NULL,
factorPG2 = NULL,
factorPG3 = NULL,
OrderX = TRUE,

# panel 7 : Barplot

Expand Down Expand Up @@ -868,7 +869,7 @@ Then, you need to choose a quantitative response variable (ex: Lenght)"
# panel 6 : Visu

outVisu <- function(){
x = NiceGraph(sr$tableF,sr$responseVarPG,sr$factorPG1,sr$factorPG2,sr$factorPG3)
x = NiceGraph(sr$tableF,sr$responseVarPG,sr$factorPG1,sr$factorPG2,sr$factorPG3,sr$OrderX)
return(x)
}

Expand All @@ -884,10 +885,13 @@ Then, you need to choose a quantitative response variable (ex: Lenght)"
observeEvent(input$factorPG3, {
sr$factorPG3 = input$factorPG3
})
observeEvent(c(sr$responseVarPG,sr$factorPG1,sr$factorPG2,sr$factorPG3), ignoreInit = TRUE, {
observeEvent(input$OrderX, {
sr$OrderX = input$OrderX
})
observeEvent(c(sr$responseVarPG,sr$factorPG1,sr$factorPG2,sr$factorPG3,sr$OrderX), ignoreInit = TRUE, {
if(sr$booTable==1){
output$PrettyG <- renderPlot({
NiceGraph(sr$tableF,sr$responseVarPG,sr$factorPG1,sr$factorPG2,sr$factorPG3)
NiceGraph(sr$tableF,sr$responseVarPG,sr$factorPG1,sr$factorPG2,sr$factorPG3,sr$OrderX)
})
}
else{
Expand Down
3 changes: 2 additions & 1 deletion inst/app/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ body <- dashboardBody(
pickerInput(inputId='factorPG1', label ='Select the factor for the x-axis (x)', ""),
##TODO: May be? Currently this will color the points based on the factor. But the expected behavior should be to color the boxplots, shouldn't it?
pickerInput(inputId='factorPG2', label ='Select a factor for coloring based on its levels (fill)', ""),
pickerInput(inputId='factorPG3', label ='Select a third factor to generate one plot per level of this factor in a grid', "")
pickerInput(inputId='factorPG3', label ='Select a third factor to generate one plot per level of this factor in a grid', ""),
checkboxInput("OrderX", "Order the X axis by median", TRUE)
)
),
fluidRow(
Expand Down

0 comments on commit 5b55239

Please sign in to comment.