First, below is my code
library(ggplot2)
x1 <- rnorm(200)
x2 <- rnorm(200,2,1)
y <- ifelse(1 + 3*x1 - x2 > 0, "1 + 3*x1 - x2 > 0", "1 + 3*x1 - x2 < 0")
z <- ifelse(-2 + x1 + 2*x2 > 0, "-2 + x1 + 2*x2 > 0", "-2 + x1 + 2*x2 < 0")
dat <- data.frame(x1,x2,y,z)
ggplot(data = dat) + geom_point(aes(x1,x2, col = y, shape = z)) +
geom_abline(intercept = 1, slope = 3, color="red", size=1.5) +
geom_abline(intercept = 1, slope = -0.5, col = "green", size = 1.5)
I want to add another legend with:
- title = "Hyperplanes"
- red solid line = "1 + 3*x1 - x2 = 0"
- green solid line = "-2 + x1 + 2*x2 = 0"
- position = bottom of the plot
Can you help me?