Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

The below is my code for plotting a graph in R but some negative values are also appearing in the graph... Why is that? Am I doing something wrong?

N = 1:100

r = 1

K = 1

r1 = list(r*N*(1 - (N/K)))

plot(N, r1[[1]])

The plot looks like:

growth rate 

1 Answer

0 votes
by (107k points)

As far as I can see at r1, the data is being plotted correctly. But the values starts from zero and decrease.

For removing the negative values, you can simply just add a scale factor like:

#add a scale factor - all values positive

r2<-r1[[1]]+10000

plot(N, r2)

or you can also perform the following:

#add a scale factor - span y = 0 

r3<-r1[[1]]+5000

plot(N, r3)

If you are a beginner and want to know more about R then do check out the following R programming tutorial that will help you in learning R from scratch. 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...