plot.prices <- function(df1234) {
  require(ggplot2)
  newdf <- get("df1234")
  env <- environment()
  g <- ggplot(df1234) +
  		 aes(x= as.Date(Date, format= "%Y-%m-%d"), y= df1234[, 3], 
              colour= brewer.pal(12,"Set3")[1]) + geom_point(size=1)

  env <- environment()
  g <- ggplot(df1234) +
  		 aes(x= as.Date(Date, format= "%Y-%m-%d"), 
  		     y= df1234[, 3] 
              )


  # ... code not shown...
  g
}

## SAMPLE DATA
spy <- read.csv(file= 'http://ichart.finance.yahoo.com/table.csv?s=SPY&d=11&e=1&f=2012&g=d&a=0&b=29&c=1993&ignore=.csv', header= T)


## ERROR
	plot.prices(spy)

## STRAIGHT, NO ERROR
  g <- ggplot(spy, aes(x= as.Date(Date, format= "%Y-%m-%d"), y= spy[, 3], 
              colour= brewer.pal(12,"Set3")[1])) + geom_point(size=1)
  g + geom_point(aes(x= as.Date(Date), y = spy[, 4], 
                 colour= brewer.pal(12,"Set3")[2]), size=1)




















#---------------- ORIGNIAL  EXAMPLE ---------------#


plot.prices <- function(df1234) {
  require(ggplot2)
  g <- ggplot(df1234, aes(x= as.Date(Date, format= "%Y-%m-%d"), y= df1234[, 3], 
              colour= brewer.pal(12,"Set3")[1])) + geom_point(size=1)
  g + geom_point(aes(x= date, y = df1234[, 4], 
                 colour= brewer.pal(12,"Set3")[2]), size=1)

  # ... code not shown...
  g
}


## SAMPLE DATA
spy <- read.csv(file= 'http://ichart.finance.yahoo.com/table.csv?s=SPY&d=11&e=1&f=2012&g=d&a=0&b=29&c=1993&ignore=.csv', header= T)


## ERROR
	plot.prices(spy)

## STRAIGHT, NO ERROR
  g <- ggplot(spy, aes(x= as.Date(Date, format= "%Y-%m-%d"), y= spy[, 3], 
              colour= brewer.pal(12,"Set3")[1])) + geom_point(size=1)
  g + geom_point(aes(x= as.Date(Date), y = spy[, 4], 
                 colour= brewer.pal(12,"Set3")[2]), size=1)
