I am trying to analyze fecundity data among ambient and heat shocked individuals in populations by comparing the number of larvae in brood 1 and brood 2 among the same population. As you can see in the data, the trend tends to be that ambient individuals have more larvae in brood 1 than brood 2 and shocked individuals produce more larvae in brood 2 than in brood 1. I am hoping to show this via a boxplot, but I am open to other suggestions of visualizing the data.
Data
ID | temp | brood 1 | brood 2 | brood avg |
---|---|---|---|---|
sa2 | ambient | 20 | 5 | 12.5 |
sa2 | ambient | 21 | 10 | 15.5 |
sa2 | shocked | 19 | 22 | 20.5 |
sa2 | shocked | 24 | 26 | 25 |
sa2 | ambient | 20 | 15 | 17.5 |
sa2 | ambient | 28 | 23 | 25.5 |
sa2 | shocked | 21 | 31 | 26 |
sa2 | shocked | 22 | 21 | 21.5 |
I have tried this code:
boxplot(fecundity.df.grouped$brood.1..[ID == "sa2"] ~ fecundity.df.grouped$temperature[ID == "sa2"],
fecundity.df.grouped$brood.2..[ID == "sa2"] ~ fecundity.df.grouped$temperature[ID == "sa2"],
col = c("lightgreen", "darkgreen"),
xlab = "temperature treatment",
ylab = "# of larvae",
names = c("brood 1", "brood 2"),
main = "sa2")
When I tried to run this, I got the following error:
Error in as.data.frame.default(data) :
cannot coerce class ‘"formula"’ to a data.frame
I have also tried this ggplot2 code but I cannot get boxplots for both brood 1 and brood 2
ggplot(data = fecundity.df.grouped, aes(x = ID, y = brood.1.. , brood.2..)) +
geom_boxplot(aes(fill = temperature), width = 0.8) + theme_bw()