I'm going back to practicing making functions at the moment and I came up with this super basic scatterplot that I'm still trying to customize a bit:
#### Quick Scatter ####
library(tidyverse)
quick.scatter <- function(data,
x.var,
y.var){
d <- data %>%
ggplot(aes(x=x.var,
y=y.var))+
geom_point(alpha=.4)+
geom_smooth(method = "lm",
color="red")+
labs(title = "Scatterplot of Data",
x="Predictor",
y="Outcome Variable")+
theme_bw()
return(d)
}
If you plug in the iris dataset for example, it should give you a quick scatter:
quick.scatter(iris,
x.var = iris$Sepal.Width,
y.var = iris$Sepal.Length)
There are a few things I want to refine with this. First, I would like to get rid of the "data" argument here so I can just plug in my values like:
quick.scatter(df$x,df$y)
Second, I want to know if there is an easy way to automatically name the x and y axis based off the variables included. So if I used the code above, I would like it to automatically have the following labels:


