I'm using a bar chart to show the income distribution of parking meters in a city. My data frame includes columns for parking meter ID, annual revenue for that meter, and which decile (1-10) that meter falls into based on its total revenue. So my command looks like this:
> rev <- ggplot(parking, aes(x=decile, y=revenue))
> rev + geom_bar(stat="identity")
And the result is exactly what I want, but I'd like to add the total revenue for each decile atop each bar in the graph, and I don't know how. I tried this:
> aggrev <- aggregate(revenue~decile, data=parking, sum)
> totals <- aggrev$revenue
> rev + geom_bar(stat="identity") + geom_text(aes(label=totals))
But I get this error message: Error: Aesthetics must either be length one, or the same length as the dataProblems:totals.
I checked length(decile) and length(totals), and their values are 4600 and 10, respectively. So I understand why this is happening, but why can't I just add any 10 characters to the 10 bars? Or to get the chart to display the bar totals automatically, maybe using "identity"? I've decided to just run this:
ggplot(aggrev, aes(x=decile,y=revenue))+geom_bar()+geom_text(aes(label=revenue))
which works, but I'd rather not have to make a new dataframe each time I want to have labels.