0
votes

I am looking to plot, in a barplot, the differences in value between two groups (Elevated Temp and Control). I'd like to be able to plot these in the same way as my original graph with Months along the x axis.

Here is the following script I have used to get to the current barplot 1 that I have plotted. This shows y axis= plant growth and x axis=Months.

Script: Current Barplot

Tempmean<- data %>% group_by (Treatment, Month) %>% summarize (TTmean = mean(Amean, na.rm=TRUE), TTsd=sd(Amean,na.rm=TRUE))


p<-ggplot(data=Tempmean, aes(x=factor(Month), y=TTmean, fill=Treatment)) +
  geom_bar(stat="identity", position="dodge", colour="black" , size = 0.25, width=0.5) + geom_errorbar(aes(ymin=TTmean-TTsd, ymax=TTmean+TTsd), width=.1,
                position=position_dodge(.5)) + scale_fill_manual(values=c("darkgray","darkolivegreen")) + scale_x_discrete(breaks=6:8,labels=c("June","July","August")) + scale_y_continuous(limits=c(0,20), breaks=seq(0,20,2))
p

This is the data I am working with 2. I would be looking to take the TTmean of the eCO2 from the TTmean of the aCO2.

Data:

    structure(list(Treatment = c("aCO2", "aCO2", "aCO2", "eCO2","eCO2", "eCO2"), Month = c(6L, 7L, 8L, 6L, 7L, 8L), TTmean = c(10.1922587348143,10.1061784054575, 8.27148533916994, 12.0261355594138,10.8954781586458, 10.9468200269188), TTsd =c(7.04936647397141,4.18653008350561, 1.50026716071241, 3.25471492346035, 0.742036555955107, 2.00464198948226)), row.names = c(NA, -6L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), vars = "Treatment", drop = TRUE, indices = list(0:2, 3:5), group_sizes = c(3L, 3L), biggest_group_size = 3L, labels = structure(list(Treatment = c("aCO2", "eCO2")), row.names = c(NA, -2L),class = "data.frame", vars = "Treatment", drop = TRUE))         
1
Please include reproducible data so we can help you with this. Eg, use dput(data), not just a picture of data. - morgan121
Thanks, please let me know if I have provided this incorrectly. - Autumnoak
if I understand your problem, you should just compute the difference between values from the different treatments. But the data you provided does not match your description i.e. there's no "TTmean" nor "month" so it is hard to come up with a solution. - Drosof
Updated. I understand the mistake. - Autumnoak

1 Answers

0
votes

This should do the trick.

I dropped TTsd because it doesn't seem like you need it. The trick is to spread() the data so you can easily compute the difference in the values. I computed as aCO2 minus eCO2; but you can change that in mutate()

library(tidyverse)
Tempmean %>%
    select(-TTsd) %>%
    # either group_by Month, or just ungroup entirely
    group_by(Month) %>%
    spread(Treatment, TTmean) %>%
    mutate(T_diff = aCO2 - eCO2) %>%
    ggplot(aes(factor(Month), T_diff)) %+%
    geom_bar(position = "dodge", stat = "identity", size = 0.25, width=0.5) %+%
    scale_x_discrete(breaks=6:8,labels=c("June","July","August"))