1

I have this df and I have created a line chart for every unique id . For every separate date, there is a different value in the column Values. And there is a 1 or o in the Bin column. I was wondering if I can represent the dots in the line chart that correspond to 1 value with another colour. thank you in advance

dput(df)
structure(list(ID = c("F1", "F1", "F1", "F1", "F1", "F1", 
"F1", "F2", "F2", "F2", "F2", "F2", "F2", "F2", "F2", "F3", "F3", 
"F3", "F3", "F3", "F3", "F3", "F3", "F3", "F4", "F4", "F4", "F4", 
"F4", "F4", "F4", "F4"), Date = c("22/6/2021", "23/6/2021", "24/6/2021", 
"25/6/2021", "26/6/2021", "27/6/2021", "28/6/2021", "22/6/2021", 
"23/6/2021", "24/6/2021", "25/6/2021", "26/6/2021", "27/6/2021", 
"28/6/2021", "29/6/2021", "22/6/2021", "23/6/2021", "24/6/2021", 
"25/6/2021", "26/6/2021", "27/6/2021", "28/6/2021", "29/6/2021", 
"30/6/2021", "22/6/2021", "23/6/2021", "24/6/2021", "25/6/2021", 
"26/6/2021", "27/6/2021", "28/6/2021", "29/6/2021"), Values = c(9.6, 
9.8, 10.2, 9.8, 9.9, 9.9, 9.9, 1.2, 1.2, 1.8, 1.5, 1.5, 1.6, 
1.4, 1.1, 3266, 3256, 7044, 6868, 6556, 3405, 3410, 3980, 5567, 
59.4, 56, 52.8, 52.4, 55.5, 54, 61, 53.6), Bin = c(0L, 0L, 1L, 
0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 
1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L)), class = "data.frame", row.names = c(NA, 
-32L))

this is the line chart

lst1 <- df %>% 
  group_split(grp =((match(ID, unique(ID)) -1) %/% 1 + 1))

ggplot(aes(x = factor(Date), y = Values)) +       
             geom_line(aes(group = ID)) + geom_point() + 
             facet_wrap(~ID, scales = 'free'))

1 Answer 1

1

You could use the color-argument:

df %>% 
  ggplot(aes(x = factor(Date), y = Values)) +       
  geom_line(aes(group = ID)) + 
  geom_point(aes(color = as.factor(Bin))) + 
  facet_wrap(~ID, scales = 'free')

returns

enter image description here

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.