I have the following data df
:
type operation year month weekday
1 A1 AAAA 2011 11 Tue
2 A1 BBBB 2011 11 Mon
3 D3 AAAA 2012 1 Tue
4 A1 AAAA 2012 1 Thu
5 D3 DDDD 2012 11 Thu
6 D3 BBBB 2013 1 Wed
Then I need to group this data by type
and operation
and calculate the number of occurances of each combination. I am currently grouping df
as follows:
grouped_data = aggregate(df,
list(type_names = df$type,
operation = df$operation),
FUN = function(x){NROW(x)})
Then I plot it using grouped barchart:
ggplot(grouped_data, aes(type_names,type)) +
geom_bar(aes(fill = operation), position = "dodge", stat="identity")+
coord_flip()
My question is how to add additional labels to bars? In particular I store some additional information about each type
in a separate data frame called add_data
. Let's say this is the popularity index (pop_ind
) of each type.
How can I attach pop_ind
values to each corresponding bar?