I am trying to create a interaction bar graph where means are to be shown above the bars.
This is the required output. I tried but in vain. Any help?
library(ggplot2)
# Create data frame
data <- data.frame(
ModeOfExpression = rep(c("Pour (less deliberate)", "Type (more deliberate)"), each = 2),
Group = rep(c("In-group cue present", "Out-group cue present"), 2),
Candies = c(2.24, 3.81, 2.59, 2.61)
)
# Create bar plot
p <- ggplot(data, aes(x = ModeOfExpression, y = Candies, fill = Group)) +
geom_bar(stat = "identity", position = position_dodge(), colour = "black") +
geom_text(aes(label = sprintf("%.2f", Candies),
y = Candies), # Avoid labeling zero values
position = position_dodge(), vjust = -0.5) +
labs(title = "Number of Candies Taken by Mode of Expression",
y = "Number of candies taken (Log + 1)",
x = "") +
scale_fill_manual(values = c("grey", "white")) +
theme_classic() +
theme(legend.position = "bottom",
legend.title = element_blank(),
plot.title = element_text(hjust = 1.5))
# Print the plot
print(p)