I am generating a scatter plot using ggplot2, and I would like to use the variable labels as the title of x axis and y axis. How can I do it? Thanks.
x0, y0 are function variables. Assume x0 has label “labelx”, and y0 has label “labely”. The code is something like this, but how do I use label as xtitle and ytitle? Thanks.
scatplot <- function(x0, y0){
ggplot(data = test, aes(x = x0, y = y0)) +
geom_point() +
geom_smooth(se = FALSE, method = "lm", color = "blue", size = 1) +
scale_x_continuous(xtitle) +
scale_y_continuous(ytitle)
}
The name of an object
xpassed to a function can be accessed withdeparse(substitute(x)).Hence, you could replace
xtitleandytitlewithdeparse(substitute(x0))anddeparse(substitute(y0)), respectively.