Menu

Reddit - Please wait for verification

Reading 0:00
15s threshold

There are times when I want to use tidyverse code and/or ggplot2 within a loop or function, and I'm never sure the best way to refer to variables. I have an example that seems to work well, but I'm wondering if this is the "best" way? Are other methods preferred? Here is my example where I'm creating boxplots using mtcars. library(dplyr) library(ggplot2) head(mtcars) plot_freq % count(.data[[var]]) ggplot(var_freq, aes(x = factor(.data[[var]]), y = n)) + geom_bar(stat = 'identity') + theme_bw() + ggtitle(label = paste0('Frequency of ', var)) } head(mtcars) plot_freq('vs') plot_freq('am') plot_freq('gear') plot_freq('carb') submitted by /u/Run_nerd [link] [comments]