Coding an R cartesian plane

3.8k views Asked by At

I'm learning R. So far I've been able to represent some functions, but I don't know how to make a cartesian plane. How do you make a cartesian plane in R?

Here's my code:

num<-400
a<-scan(n=1)
x<-c(n=num)
y<-c(n=num)
for (i in 1:num)
{
    x[i]=i
    y[i]=x[i]^2
}
plot(x,y,type="l",col="red")
title(main="Funzioni", col.main="blue", font.main=4)
1

There are 1 answers

0
josliber On BEST ANSWER

It seems like you're trying to plot the numbers 1 through 400 against their squares. You could do this with:

x = 1:400
y = x^2
plot(x, y, type="l", col="red")
title(main="Funzioni", col.main="blue", font.main=4)

Including some (empty) space for other three quadrants and some axes:

x = 1:400
y = x^2
plot(x, y, type="l", col="red", xlim=c(-400, 400), ylim=c(-16000, 16000))
abline(h=0)
abline(v=0)
title(main="Funzioni", col.main="blue", font.main=4)