I am trying to create a function that takes a data frame, an x-axis variable, and a y-axis variable to create a visual. Here's my code:
library(ggplot2)
create_visual <-
function(data, x_axis, y_axis) {
ggplot(data = data) + geom_point(mapping = aes(x = x_axis, y = y_axis))
}
When I run this code:
create_visual(penguins,flipper_length_mm,body_mass_g)
I get this error: 'Error in FUN(X[[i]], ...) : object 'flipper_length_mm' not found'
I have loaded the dataset Palmerpenguins
and checked the penguins
data table, and it does have flipper_length_mm
, yet I am getting this error. Could you please help me figure out where I am making a mistake?