uncool
uncool

Reputation: 2693

No line in plot chart despite + geom_line()

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

Upvotes: 10

Views: 50321

Answers (3)

tim
tim

Reputation: 3608

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()

Upvotes: 27

Satya
Satya

Reputation: 1800

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.

Upvotes: 0

davechilders
davechilders

Reputation: 9123

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.

Upvotes: 15

Related Questions