[R] how add objects to an svm graphic

Liaw, Andy andy_liaw at merck.com
Fri May 14 14:39:42 CEST 2004


You probably won't be able to do that without modifying plot.svm().  It
calls filled.contour() like this:

            filled.contour(xr, yr, matrix(as.numeric(preds), 
                nr = length(xr), byrow = TRUE), plot.axes = {
                axis(1)
                axis(2)
                colors <- as.numeric(model.response(model.frame(x, 
                  data)))
                points(formula, data = data[-x$index, ], col =
colors[-x$index])
                points(formula, data = data[x$index, ], pch = "x", 
                  col = colors[x$index])
            }, levels = 1:(length(unique(as.numeric(preds))) + 
                1), key.axes = axis(4, 1:length(unique(as.numeric(preds))) +

                0.5, labels = levels(preds)[unique(preds)], las = 3), 
                plot.title = title(main = "SVM classification plot", 
                  xlab = names(lis)[2], ylab = names(lis)[1]), 
                ...)
      

Note the elaborate `plot.axes=' argument.  You can try add another argument
to plot.svm, which takes an plotting expression, then plug that expression
to the end of the `plot.axes=' expression shown above.

[Note to David:  There's a typo in ?plot.svm (spelling for `vector').]

HTH,
Andy

> From: ale.ambrosi at unipd.it
> 
> Dear all,
> 
> I'm not able to solve easily the following simple problem. 
> I really hope someone can give me some hints.
> 
> I trained an svm (e1071). Now I'd like to show the results 
> graphically.
> I used plot.svm and I'd like to add some other objects to the plot:
> points, (coloured) ellipses to indicate some intersting 
> regions, curves, 
> and so on...
> I tried to pass these as additional graphics parameters to pass to 
> filled.contour, as indicated in ?plot.svm and in examples in
> filled.contour help.
> 
> But it doesn't seem to work.
> 
> Where is my foult? Can anyone help me? 
> 
> Best,
> Alessandro
> 
> 
> PS: I use R 1.9.0 on a WinXP OS
> 
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
> Alessandro Ambrosi, Ph.D.       |
> Oncological Surgical Sc. Dept.  | mail: ale.ambrosi at unipd.it
> Surg. Cl. II 			|       ambrosi at stat.unipd.it
> University of Padua		| fax:  +39 049 651891
> via Giustiniani, 2 		| tel:  +39 049 8212055
> I-35128 Padua (ITALY)           | url:  
> www.stat.unipd.it/~ambrosi 	    
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> 
> -------------------------------------------------
> This mail sent through IMP: webmail.unipd.it
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list