Draw function in ggplot - list of parameters

后端 未结 1 1923
伪装坚强ぢ
伪装坚强ぢ 2021-01-15 23:07

Simple example of a function drawing:

p <- ggplot(data = data.frame(x = 0), mapping = aes(x = x))
p + stat_function(fun = function(x) x^2 + 1*2)


        
相关标签:
1条回答
  • 2021-01-15 23:28

    Like this?

    fun1 <- function(x,a,b) a*x^2 + b
    p <- ggplot(data = data.frame(x = 0), mapping = aes(x = x))
    p + 
      stat_function(fun = fun1, args=list(a=1, b=2)) + 
      stat_function(fun = fun1, args=list(a=2, b=1), col='red') + 
      xlim(-5,5)
    

    0 讨论(0)
提交回复
热议问题