8

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

uncool
  • 2,613
  • 7
  • 26
  • 55
  • 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.. – shekeine Aug 04 '15 at 20:07
  • Does this answer your question? [Plotting lines and the group aesthetic in ggplot2](https://stackoverflow.com/questions/10357768/plotting-lines-and-the-group-aesthetic-in-ggplot2) – tjebo Oct 27 '21 at 11:03

3 Answers3

26

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()
Community
  • 1
  • 1
tim
  • 3,559
  • 1
  • 33
  • 46
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.

davechilders
  • 8,693
  • 2
  • 18
  • 18
  • 4
    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. – shekeine Aug 04 '15 at 20:19
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.

Satya
  • 1,708
  • 1
  • 15
  • 39