开发者

How can I plot multiple functions in R?

开发者 https://www.devze.com 2022-12-19 23:16 出处:网络
Using ggplot, is there a way of graphing several functi开发者_如何学Goons on the same plot? I want to use parameters from a text file as arguments for my functions and overlay these on the same plot.

Using ggplot, is there a way of graphing several functi开发者_如何学Goons on the same plot? I want to use parameters from a text file as arguments for my functions and overlay these on the same plot.

I understand this but I do not know how to add the visualized function together if I loop through.


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

精彩评论

暂无评论...
验证码 换一张
取 消