• Register
1 vote
2k views

Problem :

I am beginner to Scatter Plot. I have recently joined new project and they gave task to plot the simple best fit line to a scatterplot.

If I try to execute my below code with my data I always face the following error message:

plot(log(datatest$MEAN_intact_for),log(datatest$ERmammal_0_1), col= "blue")
title(main="Scatter plot with best-fit line", font.main= 4)
abline(lm(log(datatest$ERmammal_0_1)~log(datatest$MEAN_intact_for)), col= "red")

Please find below the error message which I receive.

“Error in formula.default(object, env = baseenv()) : invalid formula”.

I have already tried to do research on the above error but I am unable to fix it as I am very new to R So I am looking for the expert advise on above error so that I can fix it in less time.

Please Note : If I just plot my graph it works as expected but the problem comes up if I try to add a abline command to have a best fit line.

8 5 2
3,230 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution :

I can help you in fixing above error if you try to use abline() then you need to input your intercept (a) and the slope (b) as the parameters, do not just stick a lm() in there. So for example :

myfmla = lm(log(datatest$ERmammal_0_1)~log(datatest$MEAN_intact_for))

then you must try below line of code:

abline(a = myfmla$coefficients[1], b = myfmla$coefficients[2])
Hope the solution saved your time.
8 4 1
5,680 points

Related questions

0 votes
1 answer 36 views
36 views
Problem: How should I fix this issue: Error in eval(predvars, data, env) : invalid 'envir' argument of type 'character'.
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
0 answers 13 views
13 views
Problem: How should I fix this issue: Error in eval(predvars, data, env) : invalid 'envir' argument of type 'character'.
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
2 answers 1.5K views
1.5K views
Problem : I am looking for the function with the parameters such as data name as (mydata), factor as (myfactor) and variable names such as (myvar) to dynamically generate the histograms as I have to use them in lattice. I tried to do as mentioned above but error appears ... of type 'character'. I think the program doesn't know where to look for this myf` string. How should I fix this issue?
asked Dec 23, 2019 alecxe 7.5k points
0 votes
1 answer 5 views
5 views
Problem: Trying to find the predicted probability for recent_canabis_use for a male. Please someone help.
asked 3 days ago salim1 60.6k points
0 votes
1 answer 32 views
32 views
Problem: HELP: Error in terms.formula(formula, data = data) : invalid model formula in extractvars
asked Mar 14 Wafa Abu Yousef 6.1k points
1 vote
1 answer 2.3K views
2.3K views
Problem : I am facing following error : formula(formula, data = data) : invalid model formula in ExtractVars I am using the below code: install.packages("rpart") library("rpart") # you must change the below from windows to work on your linux box: mydata <- read.csv(file="c ... file to commas. I guess it is unable to read the data correctly. I am very new to the R and also a very new programmer.
asked Dec 14, 2019 alecxe 7.5k points
0 votes
1 answer 30 views
30 views
Problem: i don&rsquo;t understand about this problem please help? error in aperm.default(map, c(2, 1, 3)) : invalid first argument, must be an array
asked Apr 1 Rohit kr 17.5k points
0 votes
1 answer 860 views
860 views
Problem: I have descent knowledge in R and plot. I have gained this knowledge by attending the online tutorials. Now I have the very simple and only single data file test.txt which contains the data as shown below for your reference: 1  5  7  9  11 Now I am ... : invalid plotting method. Can some expert point out what I am doing wrong here or try to suggest the better solution for above error?
asked Jul 27, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 850 views
850 views
Problem: I have only the fundamental knowledge related to R. I want to simulate the very basic moving average process in R which is as shown below for your reference: x_t = Z_(t-1)-0.4Z_(t-2)+Z_t. Please find below my code in R: z = rnorm(500, 0, 1) x ... was unable to find the exact solution for my above error. I am looking for some help from R expert if possible to fix my above R related error.
asked Aug 12, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 858 views