I'm trying to produce bar graph with ggplot2 in R. Graph is produced perfectly so far but when I try adding sample size, it doesn't work. Here is my code:
library(ggplot2)
library(ggthemes)
library(dplyr)
library(ggsignif)
Demo1 <- demo.csv("demo.csv", header = T, sep = ",")
Demo1
mean <- aggregate(A ~ B, Demo1, mean)
sd <- aggregate(A ~ B, Demo1, sd)
samplesize <- Demo1 %>% group_by(B) %>% summarise(count = n())
X <- ggplot(Demo1, aes(y = B, x = A))
X <- X + stat_summary(fun = "mean",
geom = "bar")
X <- X + stat_summary(fun = "mean",
geom = "errorbar",
fun.min = function(x)mean(x)-sd(x),
fun.max = function(x)mean(x) + sd(x),
width = 0.1,
size = 0.5)
X <- X + theme_classic()
Then, tried to paste samplesize which I calculated in the beginning by following code.
X <- X + geom_text(aes(x = A, y = B, label = samplesize))
Is there any good way to do?
Thanks in advance.