From ?stat\_summary.

> 
> fun.data : Complete summary function. Should take data frame as input
>  and return data frame as output
> 
> 
> 

I'm having trouble understanding this. It doesn't seem like my summary function `so.summary` is being passed a data frame at all!

Code:

```
set.seed(0)
so.example <- data.frame(
  sampleID=rep(1:15)
  , sales=runif(15, 0, 1)*1000
  , revenue=runif(15, 0, 1)*10000
)

so.summary <- function(z) {
  print(z)
  data.frame(sales=median(z$sales), revenue=median(z$revenue))
}

ggplot(
  so.example
  , aes(x=sales, y=revenue)
  ) + geom_point() + stat_summary(fun.data=so.summary, geom='point', color='red')

```

Output:

```
[1] 2672.207
Error in z$sales : $ operator is invalid for atomic vectors

```