I am trying to plot a line graph using ggplot, using a fuction i call trends. I want to have the option of choosing whatever column from my df when passing it into my function wrt to the fixed column options and choosen country. Below is the code...
trends <- function(country, col){
#filtering the specified country of interest and selecting fixed columns, plus optional column to go with them.
my_data = df %>% dplyr::filter(Countries == 'country') %>%
select(col = paste0('col'), day, month)
my_plot = ggplot(my_data, aes(x=day, y=col)) + geom_line() + facet_wrap(~month)
print(my_plot)
}
trends('Cameroon', col='CFR')
but i get this error...
Error: Can't subset columns that don't exist.
x Column `col` doesn't exist.
Pls help. I have tried other suggested response to similar scenarios but to no avail.