I have a df like below and I would like to generate a plot :
df<-structure(list(AVAL = c(36.9, 37.2, 36.5, 36.7222222222222, 36.9,
36.9, 36.9, 37.2, 36.9), ADY = c(-9, -1, 1, 8, 15, 15, 15, 22,
35), PARAMCD = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
), .Label = "VSTEMP", class = "factor"), Flag = c(NA, NA, NA,
8, 15, 15, 15, 22, NA), AESER = c(NA, NA, NA, "N", "N", "N",
"N", "Y", NA)), row.names = 546:554, class = "data.frame")
ggplot(data =df)+
geom_line(data=df[!is.na(df$AVAL),],aes(x = ADY, y = AVAL, color = PARAMCD, yaxs="d", xaxs="d"),size=0.8)+
geom_point(data=df[!is.na(df$AVAL),], aes(x = ADY, y = AVAL))+
geom_vline(aes(xintercept=Flag, color=AESER),lty='dashed')
My plot is look like following:
I wonder whether it is possible to define the vertical line as black for AESER=="N", and red for AESER=="Y"? Also for the legend, is it possible to just show the one for vertical lines? or is it a better way to present the legend, maybe one block for measure item VSTERM, and then another one for AESER: Y|N? Could anyone guide me on this? Thanks.


