I want to add text of 'sum' value above the bar.
fac_report_field %>%
ggplot(aes(x = m, y = total, fill = field))+
geom_bar(stat="identity")+
scale_x_continuous(breaks = seq(1:12))+
geom_text(aes(label = total), stat = "identity" , size = 1.5,
position=position_stack(0.5))+
facet_grid(.~y)
head(fac_report_field)
# A tibble: 6 x 9
# Groups: y, m, ym [3]
y m ym field total paid others opinion plc_ratio
<fct> <dbl> <chr> <fct> <int> <int> <int> <int> <dbl>
1 2016 1 201601 Non_life 499 143 355 1 28.7
2 2016 1 201601 Life 297 100 189 8 34.6
3 2016 2 201602 Non_life 433 128 305 0 29.6
4 2016 2 201602 Life 253 82 166 5 33.1
5 2016 3 201603 Non_life 609 176 433 0 28.9
6 2016 3 201603 Life 336 94 235 7 28.6
I made new data set 'fac_report_sum' as below
> head(fac_report_sum)
# A tibble: 6 x 3
# Groups: y [1]
y m Sum
<dbl> <dbl> <int>
1 2016 1 796
2 2016 2 686
3 2016 3 945
4 2016 4 698
5 2016 5 1003
6 2016 6 1201
and add geom_text as below
fac_report_field %>%
ggplot(aes(x = m, y = total, fill = field))+
geom_bar(stat="identity")+
scale_x_continuous(breaks = seq(1:12))+
geom_text(aes(label = total), stat = "identity" , size = 1.5,
position=position_stack(0.5))+
geom_text(data = fac_report_sum, aes(label = sum, x = m, y = sum),
vjust = -.25, size = 1.5)+
facet_grid(.~y)
however there is an error as below
Error in FUN(X[[i]], ...) : object 'field' not found
Please guide me how solve this problem. Many thanks in advance.