I want to combine dplyr and ggplot within one function using piping and struggling with some issues now.
Here is the first easy one which
@Tung's answer can be simplified using {{ syntax. https://rlang.r-lib.org/reference/quasiquotation.html
library(rlang)
library(dplyr)
library(ggplot2)
foo <- function(df, y, gr, t = 4) {
df %>%
filter({{ y }}> t) %>%
ggplot(aes({{ y }})) +
geom_histogram() +
facet_grid(cols = vars({{ gr }}))
}
foo(mtcars, y = cyl, gr = vs)