2017-04-15 32 views
1

我有一個二維數據集,我已經繪製在下面。正如箭頭所指出的那樣,我想從數據集中消除兩個實驗性文物。有光澤的應用程序,以消除繪製的實驗性文物

head(df) 
data  CTCF 
1 -20000 0.9220779   
2 -19999 0.9220779   
3 -19998 0.9350649   
4 -19997 0.9350649 
5 -19996 0.9220779  
6 -19995 0.9220779 

click here to see

我從發亮庫揭示在所述數據集的點擊的點的x和y軸上的位置所取的有光澤的應用程式。

library(shiny) 

ui <- basicPage(
    plotOutput("plot1", click = "plot_click"), 
    verbatimTextOutput("info") 
) 

server <- function(input, output) { 
    output$plot1 <- renderPlot({ 
    plot(df[,1], df[,2]) 
    }) 

    output$info <- renderText({ 
    paste0("x=", input$plot_click$x, "\ny=", input$plot_click$y) 
    }) 
} 

shinyApp(ui, server) 

的文物在哪裏,但我寧願能夠操縱在那些位置數據擺脫文物這是恰好識別有用的。

有沒有人知道如何操作數據後,它已被點擊圖上?我希望能夠點擊出現僞像的區域,以便將它們反應性地設置爲平均值y軸值。更妙的是這將是冷靜,如果你可以點擊並拖動一個區域,而不是單獨點擊點......

UPDATE 我曾嘗試以下:

library(shiny) 

ui <- basicPage(
    plotOutput("plot1", click = "plot_click"), 
    tableOutput("tab") 
) 

    server <- function(input, output) { 
    output$plot1 <- renderPlot({ 
    plot(df[,1], df[,2]) 
    }) 

    output$info<-renderText({class(as.numeric(input$plot_click$x))}) 
    data_new<-eventReactive(input$plot_click,{ 
    data=df 
    data[round(as.numeric(input$plot_click$x)), 2]=mean(data[,2]) 
    data 
    }) 
output$tab<-renderTable({data_new()}) 
} 

shinyApp(ui, server) 

但輸出替換與平均值而整列不僅僅是更換點擊的位置

data CTCF  
-20000 0.71 #average of entire column 
-19999 0.71  
-19998 0.71  
-19997 0.71  
-19996 0.71 

而且我不知道有足夠的瞭解閃亮在如何處理對象能夠解決這一問題方面.... 感謝

+0

你能分享一個樣本數據嗎? – SBista

+0

嗨對不起,等待示例數據包含在頂部 –

回答

1

以取代平均單擊點更換

代碼的data[round(as.numeric(input$plot_click$x)), 2]=mean(data[,2])

data[which(data[,1] == round(as.numeric(input$plot_click$x))),2] = mean(data[,2])

點擊並在區域拖動就可以改變你的eventReactive如下:

data_new<-eventReactive(input$plot_brush,{ 
     data=df 
     rowmin <- which(data[,1] == round(as.numeric(input$plot_brush$xmin))) 
     rowmax <- which(data[,1] == round(as.numeric(input$plot_brush$xmax))) 
     data[rowmin:rowmax,2] = mean(data[,2]) 
     data 
    }) 

[編輯]:根據@ user7792658評論,我忘了在UI中提到plotOutput應該如下:

plotOutput("plot1", brush = "plot_brush") 

希望它有幫助!

+0

嗨SBista,非常感謝你的第一個策略作品!但是對於拖動:我將您的輸入$ plot_click更改爲我擁有它的方式(plot_click),並從那裏使用完全相同的代碼: data_new <-eventReactive(input $ plot_brush,{ data = df rowmin < - ..... .....等 但是當我嘗試拖動整個圖形時,它拖動整個圖形,就像一個「.png」,當我點擊它返回的單個點時:Warning:argument of長度0 –

+0

通過將plotOutput的brush參數設置爲'plot_brush'來實現它的工作 –

+0

對不起,忘了提及它。將在稍後的答案中加入,以備有人閱讀。 – SBista

相關問題