I'm trying to make multiple graphs with the apply function of R. However, I cannot make it to show the variable name in the header. I'd really appreciate it if anyone can help me with this issue.
This is the following code:
x <- c(rnorm(10), runif(10), rnorm(10,1))
y <- c(rnorm(10), runif(10), rnorm(10,1))
data <- cbind(x,y)
df <- as.data.frame(data)
apply(df, 2, plottingfunction <- function(x) {
plot(x, type= "line", main = paste("This is the graph of ", colnames(df) ))
})
The code is not going to work, however if anyone can fix it so that the graph show the name of the variable in the header would be great.
Thanks in advance for your help
