Michal Michal - 1 year ago 94
R Question

R - what is the best way to plot multiple functions $y=cx$ where c is a parameter

I want to plot the function y=cx depending on c. It is going to be number of lines going through the point (0,0).

What is the best way to do it?

I mean something like this:
enter image description here


function seems to be the way. Thanks for the help.

Answer Source

Think this should work. Not sure if it's the best way though

plot(x = 0,y = 0,xlab = "X",ylab = "Y", xlim = c(-10,10), ylim = c(-10,10))

c <- c(1:10) #Store the different values of your constant in this vector

for(i in 1:10){
   abline(coef = c(0,c[i]))

If you want different limits on your X and Y axis change the values of xlim and ylim.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download