绘制R中的s曲线函数

时间:2018-04-10 10:47:45

标签: r ggplot2

enter image description here我想绘制一条基本的s曲线。几个小时后,我学会了如何绘制x平方的函数。但是我对如何为s曲线这样做感到困惑。非常感谢你。

p1<- ggplot(data.frame(x=c(0,2)), aes(x)) + 
stat_function(fun=function(x)x^3, geom="line")

1 个答案:

答案 0 :(得分:0)

结合立方和S曲线:

ggplot(data.frame(x = c(-1, 1)), aes(x)) + 
  stat_function(fun = function(x) x^3, geom = "line")+ 
  stat_function(fun = function(x) 1/(1 + exp(-x)), geom = "line")