Interactive plotting with R raster: values on mouseover

后端 未结 2 1785
梦毁少年i
梦毁少年i 2021-02-01 19:11

I\'d like to do a small program in R for interactive visualization and modification of some raster datasets, seen as colored images. The user should open a file (from the termin

2条回答
  •  春和景丽
    2021-02-01 19:59

    I give you a simple example of how to do it in R without external Java libraries, if you want Javan's features you can adapt it, but each java graphics library is different and I have never done anything similar.

    set.seed(123)
    mydata <- data.frame(x = runif(10), y = runif(10))
    
    edit_plot <- function(data) {
      plot(data)
    
      sel <- locator(n = 1)
      if(is.null(sel)) return(TRUE)
      dd <- (data$x - sel$x)^2 + (data$y - sel$y)^2
    
      data[which.min(dd),] <- edit(data[which.min(dd),])
      r <- edit_plot(data)
      if(r) return(TRUE)
    }
    edit_plot(mydata)
    

    To exit press Esc when locator is active.

提交回复
热议问题