我有以下情况:
### GENERATING DATA
set.seed(123)
x1 = rnorm(1000)
x2 = rnorm(1000)
z = 1 + 2*x1 + 3*x2
pr = 1/(1+exp(-z))
y = pr > 0.5
y1 = ifelse(y == "TRUE", 1, 0)
ex = data.frame(y = y, y1 = y1, x1 = x1, x2 = x2)
### PLOTING THE BINOMIAL REGRESSION
library(ggplot2)
ggplot(ex, aes(x=x1, y=y1)) +
geom_point(alpha = 0.2, cex = 3) +
stat_smooth(method="glm", se=T, method.args = list(family=binomial)) +
geom_density(data = ex[ex$y1 == 0,], aes(x = x1, y = ..density..),
alpha = 0.2, fill = "tomato") +
theme_bw()
此代码为我提供了:
I need to add an inverted density plot for upper points,大概是这样的(我试着使用下面的图像代码,here可用,但没有成功):
谢谢!