Last active
October 16, 2023 10:46
-
-
Save ito4303/4ce0cf95454f911a90627cd71848eeb9 to your computer and use it in GitHub Desktop.
Use string to specify variables in aes() function of ggplot2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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