简体   繁体   中英

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

在此处输入图片说明

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM