plot - shade area between two 'ablines' in R -
I want to shade the area between the two ablines in the following code. But I could reach all those two It was to join the objection. Is this an easy way to handle? More complicated solutions are also very welcome!
x1s & lt; -c (.5,1,1,2,3,3,5, 1,3,5,4,5,5,5,6) x2s & lt; - c (3.51,2.5,2,1,1.2, 5.8,3,4,5,4,1) ys & lt; - c (Representative (+1), Representative (-1,6)) My.data & lt; - data.frame (x1 = x1s, x2 = x2s, type = as.factor (ys)) my.data library ('e1071') svm.model & lt; - svm (type ~., Data = My.data, type = 'C-classification', col = 'linear', scale = FALSE) plot (my.data [, - 3], col = (ys + 3) / 2, pch = 19, xlim = c (-1,6), ylim = c (-1,6)) digits (my data [svm.model $ index, c (1,2)], col = "blue ", Cex = 2) #Show Support Vector w & lt; - T (svm.model $ coefs)% *% svm.model $ SV b & lt; - -svm.model $ rho p & lt; - svm.model $ sv abline (a = -b / w [1,2], b = -a [1,1] / w [1,2], col = "black", lty = 1) abline (a = (-b-1) / w [1,2], B = -w [1,1] / w [1,2], col = "orange", lty = 3) abline (a = (- b + 1) / w [1,2], B = -a [1,1] / w [1,2], col = "orange", lty = 3) polygon (c (0,0), c ((- B-1) / w [1,2], (- B + 1) / w [1,2]), col = 'grey80', limit = NA)
The way I would like it to be fun is to keep the coordinates of the paths of both the rows and feed them to the polygon Cline
curve
c1 instead of abline
- curve (-b-1) / w [1,2] - x * w [1,1] / w [1,2], from = -10, to = 10, col = "orange", add = TRUE, lty = 3) C2 and LT; - curve (- B + 1) / w [1,2] - x * w [1,1] / w [1,2], from = -10, to = 10, col = "orange", plus = TRUE, lty = 3) polygon (c (c1 $ x, rev (c2 $ x)), c (c1 $ y, rev (c2 $ y)), col = "gray80"
Edit : As Julian Urvana is correctly suggested, you can use par ('usr')
to define the parameter to < / Code> and
to
automatically:
u <- par ('usr') c1 & lt; - curve ((-b - 1) / w [1,2] - x * w [1,1] / w [1,2], from = y [1], from = y [2], col = "orange", add = TRUE, Lty = 3) c2 and lt; - curve ((b + 1) / w [1,2] - x * W [1,1] / w [1,2], from = U [1], to = u [2], col = "orange", plus = TRUE, lty = 3) polygon (c (c1 $ x) , Rev (c2 $ x), c (c1 $ y, rev (c2 $ y)), col = "grey80", limit = NA)
Comments
Post a Comment