I have a big data frame with IDs, date, and test results in it - I want to run a for loop to go through all the IDs and plot a line graph that shows the evolution of the results across time, but also to add some key-indicators as points in the graph. (key indicators come from a different data frame).
Not all the IDs have all the indicators - the problem is that when I plot these points, I use dplyr
filtering to filter for ID == i
and something like key_ind != 0
. My problem is that when there are no key indicators for a certain ID, the filtered data frame has 0 observations and ggplot returns an error.
I want that when there are no points to plot (the test results still get plotted as a line) - they wont be plotted, but the line graph of the results still be plotted. Does that make sense? How can I do that? I have tried using tryCatch()
but it didn't work.