编程R:如何将多图放在同一坐标中?

时间:2021-02-06 12:05:46

I don't know how to put four plots(y=3^x, y=(1/3)^x, y=(3/2)^x, y=e^x) into a same coordinates. I typed:

我不知道如何将四个图(y = 3 ^ x,y =(1/3)^ x,y =(3/2)^ x,y = e ^ x)放入相同的坐标中。我打字:

a = function(x){y=3^x}
b = function{y=(1/3)^x}
c = function{y=(3/2)^x}
d = function(x){exp(x)}
plot(-4:4, a, b, c, d)  

but it did not work. How can I fix this?

但它不起作用。我怎样才能解决这个问题?

1 个解决方案

#1


1  

Use the add=TRUE option, Also you have your second and third functions written wrong (they take no parameters). So you have:

使用add = TRUE选项,你的第二个和第三个函数写错了(它们没有参数)。所以你有了:

a = function(x){y=3^x}
b = function(x){y=(1/3)^x}
c = function(x){y=(3/2)^x}
d = function(x){exp(x)}

and you plot using:

你使用以下绘图:

plot(a , -4 , 4)
plot(b , -4 , 4, add=TRUE)
plot(c , -4 , 4, add=TRUE)
plot(d , -4 , 4, add=TRUE)

#1


1  

Use the add=TRUE option, Also you have your second and third functions written wrong (they take no parameters). So you have:

使用add = TRUE选项,你的第二个和第三个函数写错了(它们没有参数)。所以你有了:

a = function(x){y=3^x}
b = function(x){y=(1/3)^x}
c = function(x){y=(3/2)^x}
d = function(x){exp(x)}

and you plot using:

你使用以下绘图:

plot(a , -4 , 4)
plot(b , -4 , 4, add=TRUE)
plot(c , -4 , 4, add=TRUE)
plot(d , -4 , 4, add=TRUE)