r - Trying to label bar chart ggplot2, get "Error: Aesthetics must either be length one, or the same length..." -


i'm using bar chart show income distribution of parking meters in city. data frame includes columns parking meter id, annual revenue meter, , decile (1-10) meter falls based on total revenue. command looks this:

> rev <- ggplot(parking, aes(x=decile, y=revenue)) > rev + geom_bar(stat="identity") 

and result want, i'd add total revenue each decile atop each bar in graph, , don't know how. tried this:

> aggrev <- aggregate(revenue~decile, data=parking, sum) > totals <- aggrev$revenue  > rev + geom_bar(stat="identity") + geom_text(aes(label=totals)) 

but error message: error: aesthetics must either length one, or same length dataproblems:totals.

i checked length(decile) , length(totals), , values 4600 , 10, respectively. understand why happening, why can't add 10 characters 10 bars? or chart display bar totals automatically, maybe using "identity"? i've decided run this:

ggplot(aggrev, aes(x=decile,y=revenue))+geom_bar()+geom_text(aes(label=revenue))

which works, i'd rather not have make new dataframe each time want have labels.

add totals parking dataframe:

parking$totals <- aggrev$revenue  

that allow token "totals" found in correct environment. (you may need specify x , y vector.)


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -