ggplot2 with class "varImp.train"

I have been reproducing the script from the following site:
Create predictive models in R with Caret
but when trying to replay the command:

Error in, .Call(C_palette2, NULL)) : 
  invalid graphics state

The characteristics and the class returned by the function varImp() are:

List of 3
 $ importance:'data.frame':	10 obs. of  1 variable:
  ..$ Overall: num [1:10] 77 100 82.7 38.1 93.2 ...
 $ model     : chr "loess r-squared"
 $ calledFrom: chr "varImp"
 - attr(*, "class")= chr "varImp.train"
> class(varImp(
[1] "varImp.train"

The solution I found was the following:

data[,ggplot(.SD, aes(x=reorder(name, value), y=value)) + 
  geom_bar(stat = "identity")+

Is there another way to deal with this problem?
Why in my case the command ggplot (varImp (
It was not the same as on the site?

Strange, it does work directly on my computer. The error message suggests to me it could be a problem with the previous graph you plotted, have you tried until you get back to the null device, then plotting again?

With R 4.0.0, caret_6.0-86, ggplot2_3.3.2, and lattice_0.20-41.


I closed RStudio and opened it again by running the script again and everything
What command should I put at the beginning of the script to initialize all the environment, Plot and console?
I know, separately
rm (list = ls ()) Empty Environment,
...? null device Plot
...? Ctr + L; Clear Console from keyboard

I don't feel this is necessary, personally I just use ctrl+shift+F10 to restart the R session regularly and rerun the script. Then I guess would close any open graphical device, and you could imagine something like while(dev.cur()), but in practice buggy graphical devices are rare, and ctrl+shift+F10 will close them anyway.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.