Home > Blockchain >  Is there a way to color one specific variable from a group using a different color in ggplot2/R?
Is there a way to color one specific variable from a group using a different color in ggplot2/R?

Time:10-05

I am trying to draw a specific variable (row) in a different color to make it stand out. Currently my code runs as follows:

ggplot(df, aes(x= Timepoint, y = Test))   
geom_line(aes(group=patientID, color = PatientID))  
facet_grid(~ DoseGrpDay0_D22)  
theme_bw()

Each dose group contains 10 patients and ggplot is assigning a decent rainbow color scheme to each patient. I like the color scheme and would like to keep it. However, I would like to superimpose a black line for a specific patient 4,005 to make it stand out from the rest.

CodePudding user response:

You might like to explore gghighlight e.g.:

require(gghighlight)
ggplot(df, aes(x= Timepoint, y = Test))   
  geom_line(aes(group=patientID, color = PatientID))  
  facet_grid(~ DoseGrpDay0_D22)  
  gghighlight(PatientID == 4005)  
  theme_bw()

CodePudding user response:

You can use the subset() function to create a df just has for the specific patient and use geom_point(data = patient4005, color = "black") to it.

  • Related