Skip to content

Instantly share code, notes, and snippets.

@ito4303
Last active October 16, 2023 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ito4303/4ce0cf95454f911a90627cd71848eeb9 to your computer and use it in GitHub Desktop.
Save ito4303/4ce0cf95454f911a90627cd71848eeb9 to your computer and use it in GitHub Desktop.
Use string to specify variables in aes() function of ggplot2
library(ggplot2)
library(palmerpenguins)
point_plot <- function(d, x, y) {
ggplot(d) +
geom_point(aes(x = .data[[x]], y = .data[[y]]))
}
(var_names <- colnames(penguins))
p <- point_plot(penguins, var_names[3], var_names[4])
print(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment