Skip to content
Prev 386074 / 398513 Next

How to shade area between lines in ggplot2

also from this site: https://plotly.com/ggplot2/geom_ribbon/
I get the answer is geom_ribbon but I am still missing something
```
#! plot
p = ggplot(data = trainset, aes(x=x, y=y, color=z)) +
  geom_point() + scale_color_manual(values = c("red", "blue"))
# show support vectors
df_sv = trainset[svm_model$index, ]
p = p + geom_point(data = df_sv, aes(x=x, y=y),
                   color="purple", size=4, alpha=0.5)
# show hyperplane (decision boundaries are off set by 1/w[2])
w = t(svm_model$coefs) %*% svm_model$SV  # %*% = matrix multiplication
slope_1 = -w[1]/w[2]
intercept_1 = svm_model$rho / w[2]
p = p + geom_abline(slope = slope_1, intercept = intercept_1, col =
"royalblue4")
p = p +     geom_ribbon(aes(ymin=intercept_1 - 1/w[2],
                            ymax=intercept_1 + 1/w[2],
                            x=x, fill = "band"), alpha = 0.3) +
  scale_fill_manual("",values="grey12")
```
On Fri, Oct 23, 2020 at 10:26 AM PIKAL Petr <petr.pikal at precheza.cz> wrote: