I have a df with groups in different trials, and I want to make a bar graph of just deltas between trials in ggplot. Having a hard time getting ggplot to understand I want the differences in one df. Also, some of the treatments aren't represented in the second trial, so I want to just count that as 0 (i.e. delta would be = trial 1 - 0).
set.seed(1)
df <- data.frame((matrix(nrow=175,ncol=4)))
colnames(df) <- c("group","trial","count","hour")
df$group <- rep(c("A","B","C","D","A","B","D"),each=25)
df$trial <- rep(c(rep(1,times=100),rep(2,times=75)))
df$count <- runif(175,0,50)
df$hour <- rep(1:25,times=7)
df2 <- aggregate(df[,3:4],list(df$group,df$trial),mean)
colnames(df2)[1:2] <- c("group","trial")
That's where I've gotten to. I have plotted with individual bars for (group*trial), but I can't figure out how to subtract them. I want a plot of x=group and y= delta(trial).
I tried this:
ggplot(df2 %>% group_by(group) %>% delta=diff(count),
aes(x=group,y=delta)) + geom_bar()
from a similar posting I came across, but no luck.