0

I am having trouble with creating a function that includes a filter() function. 

I keep getting an error (shown below) with this function: 

plot <- function(df, group, varx, vary) {
  df %>% 
    filter(PC == group) %>%
    ggplot(aes(x = reorder(get(varx), get(vary)), y = get(vary))) + 
    geom_col() 

} 
Error in UseMethod("filter") : 
  no applicable method for 'filter' applied to an object of class "character"

Anyone have an explanation/solution? Thanks! 

AndrewGB
  • 16,126
  • 5
  • 18
  • 49
  • To help us to help you, would you mind providing [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? – stefan Dec 06 '21 at 21:41
  • From the error message it is almost clear that `df` is a character instead of a dataframe. Also, what are you trying to achieve with `get()`? – stefan Dec 06 '21 at 21:49

0 Answers0