10

I've read documentation and I think that my code should be right, but still there is no line between the points in the output. What is wrong?

The x'axis is discrete and y'axis is continuous.

My code

 point.sqrmPrice  <- ggplot(overview.df, aes(x = areaSize, y = sqrmPrice)) + 
      geom_line() +
      geom_point() + 
      scale_y_continuous(breaks = c(seq(min(overview.df$sqrmPrice), max(overview.df$sqrmPrice), by = 10000) )) + 
      theme_bw()

enter image description here

2
  • 1
    I don't think too many SO users have overview.df in their R environment. Provide some data we can copy paste into our R installations to replicate your problem and come up with solutions.. Commented Aug 4, 2015 at 20:07
  • Does this answer your question? Plotting lines and the group aesthetic in ggplot2 Commented Oct 27, 2021 at 11:03

3 Answers 3

27

The underlying issue here is a duplicate of this stack post.

Here's a reproducible example showing what @SN248 meant about adding group to the code

ggplot(iris, aes(x = factor(Sepal.Length), y = Sepal.Width)) + 
  geom_line(aes(group=1)) + geom_point() + theme_bw()
Sign up to request clarification or add additional context in comments.

1 Comment

Oh, what is that?
15

You are not getting a line because areaSize is a factor. Convert to numeric with

overview.df$areaSize <- as.numeric(as.character(overview.df$areaSize))

and then make the plot.

1 Comment

In future, report warnings you get from functions related to your question e.g. In this case you most likely get the warning geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic which is very informative. cheers.
0

What you have to think about it is, do you expect a single line to connect all the dots?

Else, how many lines do you expect, that will tell you how many groups will you need to have.

You are missing the group aesthetic required for geom_line(), because you haven't specified how many groups (lines) you want in your plot.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.