I am attempting to create a box plot with text annotation at the top of each box (some boxes are not tall enough for the legend to represent them) but I end up having the text at the top and bottom of each box.
R version 4.0.0 Windows 7 Here is a sample data and code.
library(ggplot2)
library(ggthemes)
set.seed(42) ## for sake of reproducibility
n <- 24
dat2 <- data.frame(
Treatment=rep(c("T1", "T2", "T3", "T4", "T5", "T6"), 2),
Time=rep(c("Initial", "Final"), n/2),
Count=sample(20:300, n))
require(plyr)
require(magrittr)
dat2<-as.data.frame(dat)
dat2=
mutate(dat2,
Time=factor(Time, levels=unique(Time)))
p2.dat<-ggplot(data = dat2, aes(x = Treatment, y = Count)) +
geom_boxplot(aes(fill = Time), width = 0.8, position = position_dodge(width = 1))
p2.dat + geom_text(aes(label = paste(Time)), position = position_dodge(width = 1), vjust = -0.5, size = 4, stat = "unique", parse = TRUE)
Any help will be appreciated.

