How can I plot multiple functions in R?

后端 未结 1 1370
予麋鹿
予麋鹿 2021-02-09 19:01

Using ggplot, is there a way of graphing several functions on the same plot? I want to use parameters from a text file as arguments for my functions and overlay these on the sam

1条回答
  •  感情败类
    2021-02-09 19:39

    Here is an implementation of Hadley's idea.

    library(ggplot2)
    funcs <- list(log,function(x) x,function(x) x*log(x),function(x) x^2,  exp)
    cols <-heat.colors(5,1)
    p <-ggplot()+xlim(c(1,10))+ylim(c(1,10))
    for(i in 1:length(funcs))
        p <- p + stat_function(aes(y=0),fun = funcs[[i]], colour=cols[i])
    print(p)
    

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