I am currently doing a problem on SVM while doing a problem I came across that if y is not a factor level my plot of SVM with data is not generating but if y is factor level it generates the plot .I am not able to understand why?

set.seed(1)

x<-matrix(rnorm(20*2),ncol=2)

y<-c(rep(-1,10),rep(1,10))

x[y==1,]=x[y==1,]+1

plot(x,col=(3-y))

dat<-data.frame(x=x,y=as.factor(y))

require(e1071)

svmfit=svm(y~.,data=dat,kernel=“linear”,cost=10,scale=FALSE)

plot(svmfit,dat)

as here y is factor level but if I change the

dat<-data.frame(x=x,y=y)

the SVM plot does not generates