Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Issues creating a line chart in R. Group aesthetic error

Below is the sample data. Trying to have two lines with different colors. Seems pretty simple but running into the below error. Have two questions. First, how do I get around this error. Second, how would I edit the legend to where it says "Hires" instead of "HI".

 "geom_path: Each group consists of only one observation. Do you need to

adjust the group aesthetic?"

 library(ggplot2)


 measure <- c("HI","HI","HI","HI","HI","JO","JO","JO","JO","JO")
 date <- c("2002-01","2002-02","2002-03","2002-04","2002-05","2002-01","2002-02","2002-03","2002-04","2002-05")
 value <- c(100,105,95,145,110,25,35,82,75,90)

 df <- data.frame(measure,date,value)

  graph <- df %>% ggplot (aes(x=date, y= value, color = measure)) + geom_line () + theme (legend.position = "bottom",legend.title = element_blank())

  print(graph)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s asking for a group, so you can give it a group:

ggplot(aes(x=date, y=value, group=measure, color=measure))

It’s a bit surprising that it’s not already grouped, and I’m not exactly sure why, but the above change appears to produce the result you want:

If you’re interested in why it’s asking for a group, I’d recommend simplifying and reformatting your example, and then asking as a separate question.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading