4

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)
batpigandme
  • 147
  • 2
  • 7
  • 20
olinarr
  • 261
  • 3
  • 13

1 Answers1

4

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)
josliber
  • 43,891
  • 12
  • 98
  • 133