I am very new to R and just learnt to write simple functions. Can someone help me understand why the following function does not work.
fboxplot <- functio
The problem is that you are passing through varx and vary vectors, while the aes function expects variable names (not as strings, though). One way to fix this is to use the aes_string function to which you can pass variable names as strings (still not vectors, though):
The following should work:
fboxplot2 <- function(mydataframe, varx, vary) {
p <- ggplot(data=mydataframe, aes_string(x=varx, y=vary))
p + geom_boxplot() }
fboxplot2(df, "col1", "col2")