Feel I am making a very dumb mistake here.. as I've done this before on another project (maybe luck?)
Goal is to construct several graphs in ggplot via use of a function. I eventually want all the graphs displayed on a single page, etc...
Here is an example of a single ggplot that works:
if (require("ggplot2") == FALSE) install.packages("ggplot2")
data_df = data.frame(matrix(rnorm(200), nrow=20))
time=1:nrow(data_df)
ggplot(data=data_df, aes(x=time, y=data_df[,1])) +
geom_point(alpha=1/4) +
ggtitle(deparse(substitute(data_df[1])))
Note there are other functions that will be called within this that will change based on the dataframe column called. I followed another working example I had made, but this just gives me an error. I feel like I'm making an elementary mistake but can't put my finger on it!
if (require("ggplot2") == FALSE) install.packages("ggplot2")
data_df = data.frame(matrix(rnorm(200), nrow=20))
time=1:nrow(data_df)
graphit <- function(sample_num){
ggplot(data=data_df, aes(x=time, y=data_df[,sample_num])) +
geom_point(alpha=1/4) +
ggtitle(deparse(substitute(data_df[sample_num])))
}
graphit(1)
#Error in `[.data.frame`(data_df, , sample_num) :
# object 'sample_num' not found
Thanks for any help.