I'm trying to label the top of my geom_bar with the # of samples for my data set The following link brought me close to my solution... Use stat_summary to annotate plot with number of observations I've used in sucessfully with a geom_bar but it won't work with when I add fill. The error I get is "Error in eval(expr, envir, enclos) : object 'variable' not found". Not sure why this is or what it means?
Here is my code:
#df<-original data frame
#df2<-Averaged Count Data/# of samples within groups
###Create Labels
labels<-table(df$Distance,df$Site)
meds<-c(by(df2$count,df2$Site, max))
+geom_text(data=data.frame(), 
aes(x=names(meds), y=meds,label=paste("n =",labels)),vjust=-2)
###Plot
ggplot(df, aes(x=Distance, y=count, fill=variable))+geom_bar(stat="Identity")+
geom_text(data=data.frame(),
aes(x=names(meds), y=meds, label=paste("n =",labels)),vjust=-2)

Essentially this picture but with colors filled in. I want the colours to represent my factors in my variable category
df
     Station    Site    Distance
           1           1    0
           2           1    20
           3           1    40
           4           1    60
           1           2    0
           2           2    20
           3           2    40
           4           2    60
           5           2    80
 df1
  Station   Site    Distance    Count   variable
     1         1    0          1        a
     2         1    20         1        a
     3         1    40         1        a
     4         1    60         1        a
     1         2    0          1        a
     2         2    20         2        a
     3         2    40         2        a
     4         2    60         2        a
     5         2    80         2        a
     1         1    0          0        b
     2         1    20         0        b
     3         1    40         0        b
     4         1    60         0        b
     1         2    0          0        b
     2         2    20         1        b
     3         2    40         1        b
     4         2    60         1        b
     5         2    80         1        b
Thanks!
 
    