r - 自动检测散点图中的不同区域,然后提取并使用特定区域进行进一步绘图
问题描述
我正在开发一个闪亮的应用程序,在其中我从数据框中生成各种散点图。我希望应用程序能够检测散点图的不同区域。然后用户应该能够选择感兴趣的区域。例如
如图所示,蓝色点是散点。我希望该应用程序能够检测到如图所示的不同区域。现在,我只是画了一些垂直线和水平线,以便对所需区域进行子集化以便进一步绘图。这种方法非常繁琐,因为在每种情况下数据都会变化,因此所需区域的位置也会变化。
我尝试使用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
解决方案
推荐阅读
- python - 使用 OpenCV 从图像中识别地标和裁剪嘴的脚本看不到人脸
- r - Shiny - observeEvent 无需点击即可出现
- excel - 在 Excel 上从单行创建唯一的 SKU 行
- vba - 计算过去和未来数据的正数和负数
- c++ - 从 C++ 中的对象获取数组
- maven - 如何将 jars 上传到 Nexus?
- c# - 如何使用 OPCFoundation.NetStandard.Opc.Ua 检索 OPC 项目
- batch-file - windows - 使用批处理文件更改 REG_SZ reg 值
- bash - mac 10.13 询问密码
- php - 准备好的语句和 bind_result