geom_segment: Removed 1 rows containing missing values

11,680

Solution 1

Without looking at your example data, this is a typical warning from ggplot that is simply telling you that for some combination of the data frame you tried to plot, there was some missing data. It's nothing to worry about unless you weren't expecting any missing data. To know that, you'll need to look at your original data set.

Solution 2

It is not an error. It is a warning.

it is removing data most likely because you have NAs.


EDIT

Using the data you just gave and the code on that site I get:

enter image description here

Double check there are no NAs in your data and theta.

Share:
11,680
user1787687
Author by

user1787687

Updated on June 05, 2022

Comments

  • user1787687
    user1787687 almost 2 years

    I am working through a linear regression example for uni variate data.

    The example is listed in this webpage: http://al3xandr3.github.com/2011/02/24/ml-ex2-linear-regression.html

    Sorry for not pasting any code that I tried because I am not very familiar with R. I am a beginner.

    I read the R documentation to solve this error but I was unable to figure out the cause of this error.

    The error that I am getting is:

    Warning message:
    Removed 1 rows containing missing values (geom_segment). 
    

    The line which is causing the error is:

    ex2plot + geom_abline(intercept=theta[1], slope=theta[2])
    

    Can any one help me in solving this error.

    Sorry again, If this is a simple solution and if I am wasting your valuable time.

    Edit:

    Forgot to mention, the linear regression line that I am trying to plot using the geom_abline is not plotting.

  • user1787687
    user1787687 about 11 years
    I got the sample data from orion.math.iastate.edu/burkardt/data/regression/x01.txt. The values are not empty. The line that I am trying to plot using geom_abline is not plotting.
  • user1787687
    user1787687 about 11 years
    I looked at the dataset. I edited the lower values which are in the range 0, 10 to bigger values like in the range 40 to 100. I got the sample data from orion.math.iastate.edu/burkardt/data/regression/x01.txt. The values are not empty. The line that I am trying to plot using geom_abline is not plotting.
  • Bryan Hanson
    Bryan Hanson about 11 years
    Type theta at the console - is it empty? That would be the source of the NAs. If not, please edit your original post to include the code you are using. Sounds like there is an error in preparing the data.
  • user1787687
    user1787687 about 11 years
    It is plotting the points in the graph but, geom_abline which is supposed to plot a linear line is not plotting. Are you getting the warning? I did double check and there are no NAs in the data.
  • user1787687
    user1787687 about 11 years
    I typed theta in the console and there are NAN's .
  • user1787687
    user1787687 about 11 years
    I decreased the no.of iterations in the for loop to calculate theta value. Now I am not getting any warning and the line is plotting but not fitting the points which I will figure out.
  • user1787687
    user1787687 about 11 years
    Thank you for the answer. The problem is with the theta.
  • Bryan Hanson
    Bryan Hanson about 11 years
    Great - NaN is not the same as NA however. The latter is reserved for missing data, but NaN usually shows up when you try to compute an undefined value for instance. See ?NaN for details. Sounds like you will be fine with your troubleshooting.
  • Michal aka Miki
    Michal aka Miki almost 7 years
    I like to keep NAs in my data as indicating gaps. What is the good way to tell the plot that you need gaps there in the plot?