I'm trying to automate some graphing, without resorting to traditional loops. I'm having difficulty figuring out how to pass the elements of a row of a dataframe as the arguments of a function. The function looks like:
makeline <- function(df, var, date, ylab="",xlab="", title="", nbershade=TRUE) {
p <- ggplot(df, aes_string(x=date, y=var))
p <- p + geom_line()
# do some other magical things
}
Lets say I have a dataframe with a row as follows:
row1 <- c("corn","Price","Date")
Since corn is a dataframe ggplot choked on it as a character. Then I used corn without the quotes and since it is a dataframe with column names "Price" and "Date", I thought this would work:
mapply(makeline,row1[1],row1[2],row1[3])
Anyhow, I'm fumbling trying to figure out efficiently use this new function without resulting to looping through lists. Any pointers appreciated.