I want to annotate my plot to show the totals for each column. I have tried going over solutions shown on this site but have still been struggling. This is the data/code I am using:
data <- read_csv("Book1.csv", col_types = cols(
Year = col_factor(levels = c("2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019")),
Equity = col_factor(levels = c("LSES", "NESB", "ATSI", "DIS", "REG/REM", "WINTA")),
Count = col_integer()))
str(data)
Output (summarised):
Year : Factor w/ 9 levels "2011","2012",..
Equity: Factor w/ 6 levels "LSES","NESB",..
Count : int [1:54] 10 0 0 0 0 0 10 2 0 2 ...
Year = col_factor(levels = c("2011", "2012",..
Equity =col_factor(levels = c("LSES", "NESB", ..
Count = col_integer()_
I want to be able to say "N=10" for 2011 (the sum of all equity values for the year 2011) and repeat that for all the years across the graph.
This is the code for my graph:
library(ggplot2)
library(readr)
p <- ggplot(data, aes(fill=Equity, y=Count, x=Year)) +
geom_bar(position="fill", stat="identity")+
scale_fill_manual(values = c("#......"))+
scale_y_continuous(labels = scales::percent)+
ggtitle("Equity Distribution") +
ylab("Percentage")+xlab("")+
theme_bw() +
theme(panel.border = element_blank(),
legend.key = element_blank(),
legend.background = element_blank(),
axis.ticks = element_blank(),
panel.grid = element_blank(),
panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
panel.background = element_blank(),
plot.background = element_rect(fill = "transparent",colour = NA)
)
p
ggsave("count3.png", bg = "transparent")
I have tried this and thishere amongst others and i cant seem to get anywhere. HELP!