I am trying to add asterisks (*) to the bars of a bar chart to indicate the significance of a value using ggplot2. There are other answers to similar questions2, but I wasn't able to figure out which arguments to add to geom_text().
Here is data frame 'data':
group <- c(rep(1, 3), rep(2, 3), rep(3, 3), rep(4, 3))
n <- runif(12, 0, 25)
sig <- c("*", rep("", 11))
cluster <- rep(c("1", "2", "3"), 4)
data <- data.frame(group, n, sig, cluster)
I made a plot with an asterisk using geom_text(), but instead of being over the first bar, it is over the first group:
plot <- ggplot(data, aes(x = group, y = n, fill = cluster)) +
geom_bar(position = "dodge", stat = "identity", width = .75) +
geom_text(aes(label = sig))
How can I align the asterisk to be directly above the first bar?