I have been reproducing the script from the following site:
Create predictive models in R with Caret
but when trying to replay the command:
ggplot(varImp(model.cv))
Error in .Call.graphics(C_palette2, .Call(C_palette2, NULL)) :
invalid graphics state
The characteristics and the class returned by the function varImp() are:
str(varImp(model.cv))
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(model.cv))
[1] "varImp.train"
The solution I found was the following:
ss<-varImp(model.cv)
data<-data.table(name=row.names(ss$importance),value=ss$importance$Overall)
data[,ggplot(.SD, aes(x=reorder(name, value), y=value)) +
geom_bar(stat = "identity")+
coord_flip(),]
Is there another way to deal with this problem?
Why in my case the command ggplot (varImp (model.cv))
It was not the same as on the site?