looking at your code, it seems you can make a function to avoid repetition
subset_and_add_keyword <- function(tab, keyword) {
selectedRows <- tab[grep(keyword, tab$product), ]
selectedRows$keyword <- keyword
selectedRows
}
I think you can also make a list of your original data.frame by product, apply your function and row bind together.
Using tidyverse
, I think you can even do something like conditional addition of a column, using a (long) case_when
inside mutate with all your recoding.
To add more dates on a ggplot2 graph you need to modify scales to add breaks. See ggplot2::scale_x_date()
and scales::date_breaks()
.
Also, please, try to build a reprex so that we have some example data to help you. Without being able to run your code ourself, it is not efficient. thanks.