r-在ggplot中创建一条局部曲线


icc <- function(b, a, c) {
if (missing(c)) c <- 0
if (missing(a)) a <- 1
theta <- seq(-3, 3, .1)
P <- c + (1 - c) / (1 + exp(-a * (theta - b)))
df<- data.frame(theta,P)
ggplot(df,aes(theta,P))+
geom_smooth()+
geom_point()
}
icc(1)

我有一个函数,它使用geom_smooth((和geom_point((创建一条曲线。然而,我想这样打破这条曲线。

子集函数中创建的df

library(ggplot2)
icc <- function(b, a, c) {
if (missing(c)) c <- 0
if (missing(a)) a <- 1
theta <- seq(-3, 3, .1)
P <- c + (1 - c) / (1 + exp(-a * (theta - b)))
df<- data.frame(theta,P)
ggplot(subset(df, theta < b), aes(theta,P))+
geom_smooth()+
geom_point()+
xlim(-3, 3) +
ylim(0, 1)
}
icc(1)

最新更新