I\'m writing a function to produce time series plots of stock prices. However, I\'m getting the followi
The error occur because you use df[, 7] in gglpot2, use column name Adj.Close will fix the problem.
g <- ggplot(df, aes(x= as.Date(Date, format= "%Y-%m-%d"),
y= Adj.Close)) + geom_point(size=1)
In fact the error , it is a scoping error. aes can't find the df environnement. It tries to look for it the global scope .
if you you want to use use indexing calls , you can use aes_string for example , and manipulate strings not expressions
plot.prices <- function(df) {
require(ggplot2)
df$Date <- as.Date(df$Date, format= "%Y-%m-%d")
g <- ggplot(df, aes_string(x= 'Date',
y= colnames(df)[7])) + geom_point(size=1)
# ... code not shown...
g
}
