Define a function, see this example with the iris dataset:
library(tidyverse)
custom_function <- function(variable) {
group_by(iris, {{variable}}) %>%
ggplot(aes(x = Sepal.Length, y = Sepal.Width, color = {{variable}})) +
theme(axis.text.x = element_text(angle = 90), legend.position="bottom",
legend.text = element_text(size=10)) +
geom_point() + geom_line(aes(group = {{variable}}), lty = 1)
}
custom_function(Species)
Created on 2021-02-09 by the reprex package (v1.0.0)
If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.