0

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()
J Phelps
  • 1
  • 1
  • 1
    Please share your data.frame or at least a sample of it. I.e. `dput(fecundity.df.grouped)` – Ric Jan 23 '23 at 21:34
  • 1
    You've sent two formulas to the boxplot call, and no data. The boxplot function is trying to use one of the formulas as data. – Isaiah Jan 23 '23 at 22:06
  • 1
    Please provide enough code so others can better understand or reproduce the problem. – Community Jan 23 '23 at 22:57
  • This answer - https://stackoverflow.com/a/11347017/496803 - pretty much covers your issue I believe - you will need to stack your data first so you have one column with the values to be plotted, and one column that is your grouping variable. – thelatemail Jan 23 '23 at 23:55

0 Answers0