• Register
1 vote
1.4k 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
5,680 points

Related questions

1 vote
1 answer 1.9K views
1.9K 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
2 answers 1.3K views
1.3K 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 698 views
698 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 606 views
606 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 621 views
0 votes
1 answer 813 views
813 views
Problem : I want to use the neural net for predictions. I am trying to create some X as follows : x <- cbind(seq(1, 50, 1), seq(51, 100, 1)) I am trying to create some Y as follows : y <- x[,1]*x[,2] Give them the names as follows colnames(x) ... =0.01) error in terms.formula(formula) : '.' in formula and no 'data' argument Does anybody have any idea regarding the error I am facing? Any solution?
asked Dec 11, 2019 alecxe 7.5k points
0 votes
1 answer 13 views
13 views
Problem: error in sort(y) : argument "y" is missing, with no default.
asked Feb 16 charles mathews 3.9k points
0 votes
1 answer 62 views
1 vote
1 answer 1.3K views
1.3K views
Problem : Currently I am learning the r programming. I am unable to find the answer to below error but I am unable to do so. Currently I have one dataframe it has a column of strings. My task is to count the exact number of characters present in each entry of ... , with no default Error in match.fun(FUN): argument "FUN" is missing, with no default Can someone guide me in fixing above error?
asked Mar 30, 2020 morrisBson 3.2k points
0 votes
1 answer 206 views
206 views
Problem : I have done a lot of research on this extensively without finding any solution on it. I have tried cleaning my data set as follows: library("myraster") impute.mean <- function(l) replace(l, is.na(l) | is.nan(l) | is.infinite(l) , mean(l, na.rm = TRUE)) losses <- ... TRUE, na.rm=TRUE, nan.rm=TRUE) All my research says it should be NA's or Inf's or NaN's in the data but I don't have any
asked Dec 5, 2019 alecxe 7.5k points