0

I am trying to add lines to a very simple plot but it does not work. Why does this happen. I want to unite the points via those lines.

month<-c("Jan","Feb")
EA<-c(52.986,52.086)
df<-data.frame(month,EA)

ggplot(data=df,aes(x=month, y=EA)) + geom_point()+geom_line()
firmo23
  • 7,490
  • 2
  • 38
  • 114

1 Answers1

1

In this case you have to add group = 1 to your aesthetics:

library(ggplot2)
month <- c("Jan", "Feb")
EA <- c(52.986, 52.086)
df <- data.frame(month = factor(month, unique(month)), EA)

ggplot(df, aes(x = month, y = EA, group = 1)) + 
    geom_point() +
    geom_line()

Created on 2020-05-07 by the reprex package (v0.3.0)

see: ggplot2 line chart gives "geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?"

user12728748
  • 8,106
  • 2
  • 9
  • 14