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

1 Answer 1

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?"

Sign up to request clarification or add additional context in comments.

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.