diff --git a/server.R b/server.R index f2656da..b84d77c 100644 --- a/server.R +++ b/server.R @@ -10,6 +10,8 @@ suppressPackageStartupMessages({ library(car) library(plotly) library(openxlsx) + library(ggplot2) + library(ggrepel) }) options(stringsAsFactors = FALSE) @@ -849,6 +851,29 @@ shinyServer(function(input, output) { plotOutput('runPCA', width = paste(input$width,"%",sep = ""), height = input$height, click = "plot_click") }) + output$plotMDS <- renderUI({ + plotOutput('runMDS', width = paste(input$width,"%",sep = ""), + height = input$height) + }) + output$runMDS <- renderPlot({ + if (!input$displayMDS) return(NULL) + dat2 <- getgenind() + + obj <- genind2genpop(dat2) + dst <- dist.genpop(obj, method = 1) + # hc <- hclust(dst) + # plot(as.dendrogram(hc), horiz=T, xlab = "", sub = "", main = "Nei's distance between populations") + + MDS <- cmdscale(dst) + MDS <- data.frame(ax1 = MDS[, 1], ax2 = MDS[, 2], pop = rownames(MDS)) + # plot(MDS, xlab = "MDS Axis 1", ylab = "MDS Axis 2", pch = 16, col = dat2@pop) + p <- ggplot(MDS, aes(x=ax1, y=ax2, color = pop, label = pop)) + + geom_point() + + geom_text_repel() + + labs( x = "MDS Axis 1", y = "MDS Axis 2", title = "MDS based on Nei's distance") + + theme_minimal() + plot(p) + }) # DL principal components output$dlPCAeigen <- downloadHandler( diff --git a/ui.R b/ui.R index facad51..1fd8001 100644 --- a/ui.R +++ b/ui.R @@ -298,9 +298,13 @@ shinyUI( downloadButton('dlFstMatXL', 'Download as Excel (.xlsx)') ), - tags$hr(), + tags$hr() - h4("Principal Component Analysis"), + ), + tabPanel( + "PCA - MDS", + + h4("Principal Component Analysis (PCA)"), checkboxInput( 'displayPCA', @@ -333,7 +337,20 @@ shinyUI( ), - tags$hr() + tags$hr(), + + h4("Multidimensional Scaling (MDS) based on Nei's distance"), + + checkboxInput( + 'displayMDS', + "Compute Nei's genetic distance between populations and run MDS", + FALSE + ), + conditionalPanel( + + condition = "input.displayMDS == true", + uiOutput('plotMDS') + ) ), tabPanel( @@ -465,6 +482,7 @@ shinyUI( h3("Updates"), tags$ul( + tags$li("1.4.0 (09/02/2021) – STRAF can now perform an MDS. All results can be downloaded as Excel files. Minor bug fixes in file conversion."), tags$li("1.3.3 (03/02/2021) – Minor bug fixes in file conversion and PIC computation. Improved graphics."), tags$li("1.3.0 (01/02/2021) – STRAF can convert files to the Genepop and Familias formats. A File conversion tab has been added."), tags$li("1.2.2 (09/01/2021) – STRAF has moved to an AWS server (without any changes in the License)."),