首页 > 解决方案 > 自动检测散点图中的不同区域,然后提取并使用特定区域进行进一步绘图

问题描述

我正在开发一个闪亮的应用程序,在其中我从数据框中生成各种散点图。我希望应用程序能够检测散点图的不同区域。然后用户应该能够选择感兴趣的区域。例如 在此处输入图像描述

如图所示,蓝色点是散点。我希望该应用程序能够检测到如图所示的不同区域。现在,我只是画了一些垂直线和水平线,以便对所需区域进行子集化以便进一步绘图。这种方法非常繁琐,因为在每种情况下数据都会变化,因此所需区域的位置也会变化。

我尝试使用plotly_brush功能,它可以工作,但对我来说不是理想的方式。

有没有办法自动检测散点图中的不同区域并使用特定区域进行进一步处理?

PS。我无法在这个问题中包含我的数据框,因为它们太大了。

这是我的尝试:

data <- reactive({
    req(input$file)
    df <- read.table(file=input$file$datapath[input$file$name==input$Select], skip = 15, sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)
    updateSelectInput(session, inputId = 'xcol', label = 'X Variable',
                      choices = names(df), selected = names(df)[1])
    updateSelectInput(session, inputId = 'ycol', label = 'Y Variable',
                      choices = names(df), selected = names(df)[2])
    return(df)
  })

      x1 <- data()[, c(input$xcol1, input$ycol1)]
      x1[x1 == ""] <- NA
      M <- na.omit(x1)
      #plot
      g <- ggplot(data =  M) + theme_bw() +
        geom_point(aes_string(x= M[,1], y= (M[,2]-min(M[1,2]))),colour = "blue", size =0.1)
      g

标签: rggplot2shiny

解决方案


推荐阅读