I have some question regarding how to plot line graph in R with data containing NA value. Here is an extract of the data:
x | y |
---|---|
NA | 8 |
3 | NA |
NA | 9 |
-3.11 | 2.37 |
-2.90 | 2.45 |
-3.45 | 2.02 |
I tried to do the following:
plot(na.omit(df$x), na.omit(df$y), type="l",
main="y vs x",
xlab="x",
ylab="y")
I got the error like this:
xy.coords(x, y, xlabel, ylabel, log) Error: 'x' and 'y' lengths differ
(a) How do I plot using the basic R plot function? (b) How do I plot using the GGplot2?
Thanks in advance.
-Updated-
When I plot a line graph in R, the graph goes from x=-3.11 to x=-2.90 to x=-3.45. How do I arrange it so that the graph goes from x=-3.45 to x=-3.11 to x=-2.90?
-Solved-
I have found the solution to the above question. Just sort the data frame first. df <- df[order(df$x), ]