My question is related to the second answer to this question and also my previous question (posted below).
Proper way to plot multiple data series in ggplot with custom colors, legend etc
How is it possible to plot a subset of lines according to user's needs (i.e. first and third, all four etc.)? Currently I am using base plot()
and would like to change to ggplot2
solution. I need to address that the time series have uneven lengths, as in the original question. I was experimenting with the syntax simialr to the following, but without success:
ggplot(data = dat, aes(x=x, y=y)) + geom_line(aes(y = y[dat$grp == "a"], colour=grp)) + geom_point()
Error: Aesthetics must be either length 1 or the same as the data (20): y, colour, x
P.S.: For those interested, this is what I am trying to do (I keep my previous question updated, however I am the only one posting there): I am trying to build this functionality into my Shiny application. I.e. user chooses a number of parameters, which I convert to a set of IDs which correspond to a subset of time series in my dataframe and the plot outputs the chosen subset of lines.
Shiny + ggplot2: plotting a number of lines in one graph based on user input