简体   繁体   English

如何在R中绘制多个函数?

[英]How can I plot multiple functions in R?

Using ggplot, is there a way of graphing several functions on the same plot? 使用ggplot,有没有一种方法可以在同一个图上绘制几个函数? 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. 这是Hadley的想法的实现。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM