Home > Software engineering >  Cannot store results from identify
Cannot store results from identify

Time:06-12

I want to store the results from my click with identify on my plot. The issue I am having is that the interaction with the plot is not from identify but all plots are plotted. However, I have found that sometimes identify will work but most times it will not, how can I correctly implement identify within my function and store the results as a vector?

some_func <- function(data, response, predictors, label){
  form <- reformulate(predictors, response=response)
  mod <- lm(form, data)
  dfb_mod <- dfbeta(mod)[,-1] %>% data.frame() %>% as.list()
  par(mfrow=c(2, 2))
  xlabel <- names(dfb_mod)
  ident_labels <- data[, label]
  #return(ident_labels)
  a <- mapply(function(x, y)plot(x, xlab=y, ylab='response') %>% with(abline(h=0)) %>% with(identify(., names=ident_labels)), dfb_mod, xlabel)
  return(a)
}

require(faraway)
data(savings)
savings2 <- savings %>% rownames_to_column()
some_func(savings2, 'sr', c('pop15', 'pop75', 'dpi', 'ddpi'), 'rowname') 

CodePudding user response:

Your piping of the plotting functions doesn't make much sense. Write your mapply like this:

  a <- mapply(
    function(x, y) {
      plot(x, xlab=y, ylab='response') 
      abline(h=0)
      identify(x, labels = ident_labels)
    }, 
    dfb_mod, xlabel
  )

Now it should work.

  •  Tags:  
  • r
  • Related