ggplot multiple line plot grouped by ID and class

I want to generate a multiple line plot, grouped on userID, but with subjects in two classes. I'd like to different colors for the lines of the two groups. (I also have a smooth, but that works OK.) I have to use the group parameter to tell the program which points to connect, but I can''t figure out how to tell the program to use different colors for the two "classes" of subjects. Any help showing me the needed magic would be gratefully received.
Larry Hunsicker

Fsigt6a %>% filter(is.na(flag)) %>%
  ggplot(aes(12*dptp1/365.25, AIRg, group=cpid)) +
  geom_line() + 
  geom_smooth(group = 1, se = F, color = 'red') + 
  labs(x = "Months relative to first PHPI transplant", 
       title = "Course of AIRg, CIT-06 subjects")

fsigt..pdf (2.7 KB)

I am unsure which column of your data you want to use to color the lines. If it is cpid, then add color = cpid to the aes()

Fsigt6a %>% filter(is.na(flag)) %>%
  ggplot(aes(12*dptp1/365.25, AIRg, group=cpid, color = cpid)) +
  geom_line() + 
  geom_smooth(group = 1, se = F, color = 'red') + 
  labs(x = "Months relative to first PHPI transplant", 
       title = "Course of AIRg, CIT-06 subjects")

If that is not what you want, please make a Reproducible Example of data and explain which column designates a group and which a class.

1 Like

Ahhh! It was "color = numTp", not "col = numTp". So easy. That was it exactly. Many thanks.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.