﻿_id,#contains basic steps from the raw csv file
1,
2,
3,"adu <- read.csv(file=""C:/Users/host database.csv"""
4,adu$end_date <- as.Date(adu$end_date
5,adu$days<-as.numeric(difftime(adu$end_date
6,
7,#survival and cox regression:
8,library(survival)
9,adu$inf <- factor(adu$inf
10,
11,# Create a survival object
12,surv_obj <- Surv(time = adu$days
13,#the models:
14,cox_model <- coxph(surv_obj ~ inf + tempi
15,cox_modeli <- coxph(surv_obj ~ inf * tempi
16,
17,# Set options to display coefficients without scientific notation
18,options(scipen = 999)
19,
20,summary(cox_model)
21,summary(cox_modeli)
22,AIC(cox_model)
23,AIC(cox_modeli)
24,
25,# Compute residuals for the best model
26,martingale_res <- residuals(cox_model
27,deviance_res <- residuals(cox_model
28,
29,# Plot Martingale residuals
30,plot_martingale <- function(residuals) {
31,  plot(residuals
32,"       main = ""Martingale Residuals"")"
33,  abline(h = 0
34,}
35,plot_martingale(martingale_res)
36,
37,# Plot Deviance residuals
38,plot_deviance <- function(residuals) {
39,  plot(residuals
40,"       main = ""Deviance Residuals"")"
41,  abline(h = 0
42,}
43,plot_deviance(deviance_res)
44,
45,#just 26:
46,c26<-subset(adu
47,surv_obj26 <- Surv(time = c26$days
48,# Fit Cox proportional hazards model
49,cox_model26 <- coxph(surv_obj26 ~ inf 
50,summary(cox_model26)
51,
52,
53,
54,
55,#removing mussels that died before dissection and mussels that were not representative of their infection category for growth
56,ass<- subset(adu
57,as<- subset(ass
58,
59,as$growth<-as$Growth / 10
60,asg<-subset(as
61,asr<- subset(as
62,asr$CI1<- as.numeric(asr$CI1)
63,
64,#colours so that control is green and infected mussels blue and purple based on parasite:
65,"inf_colors3 <- c(""0"" = ""green"""
66,
67,#growth model selection
68,#was data deficient: g0 <- lmer(growth ~  parasite_number * days *tempi *inf+ (1 | tank)
69,g0 <- lmer(growth ~  parasite_number + days *tempi *inf+ (1 | tank)
70,summary(g0)
71,g11<- lm(growth ~  parasite_number * days *tempi *inf
72,summary(g11)
73,g1<- lm(growth ~  parasite_number + days *tempi *inf
74,summary(g1)
75,g2<- lm(growth ~  parasite_number + days +tempi *inf
76,summary(g2)
77,g3<- lm(growth ~  parasite_number + days +tempi +inf
78,summary(g3)
79,g4<- lm(growth ~  days +tempi +parasite_number *inf
80,summary(g4)
81,g51<- lm(growth ~  days *tempi *inf
82,summary(g51)
83,g52<- lm(growth ~  days *tempi +inf
84,summary(g52)
85,g53<- lm(growth ~  days +tempi *inf
86,summary(g53)
87,g5<- lm(growth ~  days +tempi +inf
88,summary(g5)
89,g6 <- lmer(growth ~  days +tempi +inf+ (1 | tank)
90,summary(g6)
91,anova(g1
92,
93,AIC(g0)
94,AIC(g11)
95,AIC(g1)
96,AIC(g2)
97,AIC(g3)
98,AIC(g4)
99,AIC(g51)
100,AIC(g52)
101,AIC(g53)
102,AIC(g5)
103,AIC(g6)
104,
105,# Checking the fit of the best model
106,residuals <- residuals(g5)
107,
108,# Create diagnostic plots
109,par(mfrow=c(2
110,plot(g5)
111,
112,#three influential points detected. First trying out how much they affect the results: 
113,# Create a vector of numbers to exclude
114,"exclude_numbers <- c(""E48"""
115,
116,# Subset the data to exclude the influential points
117,asg_subset <- subset(asg
118,
119,g5wo_outliers<- lm(growth ~  days +tempi +inf
120,summary(g5wo_outliers)
121,
122,#reproduction model selection:
123,# Fit a negative binomial mixed-effects model
124,
125,# Sample mean and variance excluding NAs
126,mean_val <- mean(as$repro
127,var_val <- var(as$repro
128,
129,mean_val
130,var_val
131,
132,# Method of Moments estimation of theta
133,theta_mom <- mean_val^2 / (var_val - mean_val)
134,
135,#first with the random effect:
136,g1 <- glmer(repro ~  days *tempi *inf+ (1 | tank)
137,summary(g1)
138,g2 <- glmer(repro ~  days +tempi *inf+ (1 | tank)
139,summary(g2)
140,g2 <- glmer.nb(repro ~ days + tempi * inf + (1 | tank)
141,g3 <- glmer(repro ~  days +tempi +inf+ (1 | tank)
142,summary(g3)
143,#all with tank result in singularity issues!
144,
145,# Fit the model without any random effects using glm
146,r0<- glm(repro ~ days + parasite_number + tempi * inf
147,         family = negative.binomial(theta = 3.0)
148,         data = as)
149,r01<- glm(repro ~ days * parasite_number * tempi * inf
150,         family = negative.binomial(theta = 3.0)
151,         data = as)
152,r02<- glm(repro ~ days  + tempi * inf * parasite_number
153,         family = negative.binomial(theta = 3.0)
154,         data = as)
155,r03<- glm(repro ~ days + parasite_number + tempi + inf
156,         family = negative.binomial(theta = 3.0)
157,         data = as)
158,r1<- glm(repro ~ days * tempi * inf
159,         family = negative.binomial(theta = 3.0)
160,         data = as)
161,r12<- glm(repro ~ days + tempi * inf
162,         family = negative.binomial(theta = 3.0)
163,         data = as)
164,r13<- glm(repro ~ days * tempi + inf
165,          family = negative.binomial(theta = 3.0)
166,          data = as)
167,r2<- glm(repro ~ days + tempi + inf
168,         family = negative.binomial(theta = 3.0)
169,         data = as)
170,summary(r0)
171,summary(r01)
172,summary(r02)
173,summary(r03)
174,summary(r1)
175,summary(r12)
176,summary(r13)
177,summary(r2)
178,
179,#condition:
180,g1<- lm(CI2_fixed ~  parasite_number + days *tempi *inf
181,summary(g1)
182,g11<- lm(CI2_fixed ~  parasite_number * days *tempi *inf
183,summary(g11)
184,g2<- lm(CI2_fixed ~  parasite_number + days +tempi *inf
185,summary(g2)
186,g3<- lm(CI2_fixed ~  parasite_number + days +tempi +inf
187,summary(g3)
188,g4<- lm(CI2_fixed~  days +tempi +parasite_number *inf
189,summary(g4)
190,g5<- lm(CI2_fixed ~  days +tempi +inf
191,summary(g5)
192,g6 <- lmer(CI2_fixed ~  days +tempi +inf+ (1 | tank)
193,summary(g6)
194,g7<- lm(CI2_fixed ~  days +tempi *inf
195,summary(g7)
196,g71<- lm(CI2_fixed ~  days *tempi +inf
197,summary(g71)
198,g8 <- lmer(CI2_fixed ~  days +tempi *inf+ (1 | tank)
199,summary(g8)
200,anova(g1
201,
202,AIC(g1)
203,AIC(g11)
204,AIC(g2)
205,AIC(g3)
206,AIC(g4)
207,AIC(g5)
208,AIC(g6)
209,AIC(g7)
210,AIC(g71)
211,AIC(g8)
212,
213,# Checking the fit of the best model
214,residuals <- residuals(g7)
215,
216,# Create diagnostic plots
217,par(mfrow=c(2
218,plot(g7)
219,
220,
221,
222,#Figures
223,
224,#kaplan-meier:
225,# Create a survival object
226,surv_obj <- Surv(time = adu$days
227,
228,# Fit Kaplan-Meier survival curves by 'inf'
229,km_fit <- survfit(surv_obj ~ inf
230,
231,# Plot Kaplan-Meier survival curves
232,plot(km_fit
233,"     xlab = ""Time (Days)"""
234,"     main = ""Kaplan-Meier Survival for all temperatures"")"
235,
236,# Fit Kaplan-Meier survival curves by 'temp'
237,km_fit <- survfit(surv_obj ~ temp
238,
239,# Plot Kaplan-Meier survival curves
240,plot(km_fit
241,"     xlab = ""Time (Days)"""
242,"     main = ""Kaplan-Meier Survival for all temperatures"")"
243,
244,# Fit Kaplan-Meier survival curves by 'temp' and 'inf'
245,km_fit <- survfit(surv_obj ~ temp+inf
246,
247,# Plot Kaplan-Meier survival curves
248,plot(km_fit
249,"     xlab = ""Time (Days)"""
250,"     main = ""Kaplan-Meier Survival for all temperatures"")"
251,
252,
253,# Subset the data
254,c26 <- subset(adu
255,c18 <- subset(adu
256,c14 <- subset(adu
257,
258,# Function to create the plots
259,create_plots <- function() {
260,  # Set up a 1x3 layout for the plots with adjusted margins
261,  par(mfrow = c(1
262,
263,  # Custom parameters for thicker lines and increased font size
264,  par(cex = 1.2
265,
266,  # Plot for 14 C
267,  surv_obj14 <- Surv(time = c14$days
268,  km_fit14 <- survfit(surv_obj14 ~ inf
269,  plot(km_fit14
270,"       xlab = """""
271,"       main = ""14 C"""
272,  grid()
273,
274,  # Plot for 18 C
275,  surv_obj18 <- Surv(time = c18$days
276,  km_fit18 <- survfit(surv_obj18 ~ inf
277,  plot(km_fit18
278,"       xlab = ""Time (days)"""
279,"       main = ""18 C"""
280,  grid()
281,
282,  # Add legend with increased font size
283,"  legend(""bottom"""
284,"         col = c(""green"""
285,         text.font = 2)  
286,
287,  # Plot for 26 C
288,  surv_obj26 <- Surv(time = c26$days
289,  km_fit26 <- survfit(surv_obj26 ~ inf
290,  plot(km_fit26
291,"       xlab = """""
292,"       main = ""26 C"""
293,  grid()
294,}
295,
296,# Save as EPS
297,setEPS()
298,"postscript(""output.eps"""
299,create_plots()
300,dev.off()
301,
302,# Save as TIFF
303,"tiff(""output.tiff"""
304,create_plots()
305,dev.off()
306,
307,
308,#growth figure
309,
310,#mussel growth over time without excluding negative values:
311,t10<- subset(as
312,t14<- subset(as
313,t18<- subset(as
314,t22<- subset(as
315,t26<- subset(as
316,
317,#colours so that control is green and infected mussels blue and purple based on parasite:
318,"inf_colors3 <- c(""0"" = ""green"""
319,
320,"new_legend_labels <- c(expression(""Control"")"
321,
322,p10g <- ggplot(t10
323,  geom_point(size = 3) +
324,"  labs(title = ""     10 C"""
325,"       x = ""Days"""
326,"       y = """") +"
327,  scale_y_continuous(breaks = seq(0
328,                     limits = c(-0.5
329,  scale_color_manual(values = inf_colors3
330,  theme_minimal()+
331,  theme(
332,    plot.title = element_text(size = 10)   ) + 
333,scale_x_continuous(limits = c(55
334,
335,# Ensure the legend is positioned at the bottom
336,"p10g <- p10g + theme(legend.position = ""bottom"")"
337,
338,p14g <- ggplot(t14
339,  geom_point(size = 3) +
340,"  labs(title = ""     14 C"""
341,"       x = """""
342,"       y = """") +"
343,    scale_y_continuous(breaks = seq(0
344,                     limits = c(-0.5
345,  scale_color_manual(values = inf_colors3) +
346,  theme_minimal()+
347,  theme(
348,    plot.title = element_text(size = 10)   ) + 
349,scale_x_continuous(limits = c(55
350,
351,p18g <- ggplot(t18
352,  geom_point(size = 3) +
353,"  labs(title = ""     18 C"""
354,"       x = """""
355,"       y = ""Growth (mm)"") +"
356,  scale_y_continuous(breaks = seq(0
357,                     limits = c(-0.5
358,  scale_color_manual(values = inf_colors3) +
359,  theme_minimal()+
360,  theme(
361,    plot.title = element_text(size = 10)   ) + 
362,scale_x_continuous(limits = c(55
363,
364,p22g <- ggplot(t22
365,  geom_point(size = 3) +
366,"  labs(title = ""     22 C"""
367,"       x = """""
368,"       y = """") +"
369,  scale_y_continuous(breaks = seq(0
370,                     limits = c(-0.5
371,  scale_color_manual(values = inf_colors3) +
372,  theme_minimal()+
373,  theme(
374,    plot.title = element_text(size = 10)   ) + 
375,scale_x_continuous(limits = c(55
376,
377,p26g <- ggplot(t26
378,  geom_point(size = 3) +
379,"  labs(title = ""b.   26 C"""
380,"       x = """""
381,"       y = """") +"
382,  scale_y_continuous(breaks = seq(0
383,                     limits = c(-0.5
384,  scale_color_manual(values = inf_colors3) +
385,  theme_minimal()+
386,  theme(
387,    plot.title = element_text(size = 10)   ) + 
388,scale_x_continuous(limits = c(55
389,
390,#version where the left side of Figure 3 has growth over time:
391,as$gtime<-as$growth / as$days
392,
393,#growth flipped:
394,growthall2 <- ggplot(as
395,  geom_boxplot() +
396,  coord_flip() +  # To flip the x and y axes
397,scale_y_continuous(breaks = seq(-0.01
398,                   limits = c(-0.01
399,"  ggtitle(""a."") +"
400,"  xlab(""Temperature ( C)"") +  # Add x-axis label"
401,"  ylab(""Mussel growth (mm/day)"") +   # Add y-axis label"
402,  scale_fill_manual(values = inf_colors3)
403,
404,# Increase font size 
405,custom_theme <- theme(
406,  axis.title = element_text(size = 14)
407,  axis.text = element_text(size = 12)
408,  legend.text = element_text(size = 12)
409,  legend.title = element_text(size = 12)
410,  plot.title = element_text(size = 12)
411,  strip.text = element_text(size = 14)       
412,)
413,
414,# Apply the custom theme to each plot
415,"growthall2 <- growthall2 + theme(legend.position = ""none"") + custom_theme"
416,"p10g <- p10g + theme(legend.position = ""bottom"") + custom_theme"
417,"p14g <- p14g + theme(legend.position = ""none"") + custom_theme"
418,"p18g <- p18g + theme(legend.position = ""none"") + custom_theme"
419,"p22g <- p22g + theme(legend.position = ""none"") + custom_theme"
420,"p26g <- p26g + theme(legend.position = ""none"") + custom_theme"
421,
422,# Define the layout for reproall and other plots
423,growthall_layout <- ggarrange(growthall2
424,
425,other_plots <- ggarrange(p26g
426,                         ncol = 1
427,
428,# Combine reproall and other plots
429,grouped_plot <- ggarrange(growthall_layout
430,                          widths = c(1
431,                          common.legend = TRUE
432,
433,# Display the grouped plot
434,print(grouped_plot)
435,
436,"ggsave(""growth0706final.tiff"""
437,
438,
439,#condition index figure :
440,#mussel CI2 over time:
441,t10<- subset(asr
442,t14<- subset(asr
443,t18<- subset(asr
444,t22<- subset(asr
445,t26<- subset(asr
446,
447,#colours so that control is green and infected mussels blue and purple based on parasite:
448,"inf_colors3 <- c(""0"" = ""green"""
449,#condition flipped:
450,CI2all <- ggplot(asr
451,  geom_boxplot() +
452,  coord_flip() +  # To flip the x and y axes
453,scale_y_continuous(breaks = seq(1
454,                     limits = c(0.5
455,"  ggtitle(""a."") +"
456,"  xlab(""Temperature ( C)"") +  # Add x-axis label"
457,"  ylab(""Mussel condition"") +   # Add y-axis label"
458,  scale_fill_manual(values = inf_colors3)
459,
460,CI2all
461,
462,"new_legend_labels <- c(expression(""Control"")"
463,
464,p10g <- ggplot(t10
465,  geom_point(size = 3) +
466," # geom_smooth(method = ""lm"""
467,"  labs(title = ""     10 C"""
468,"       x = ""Days"""
469,"       y = """") +"
470,  scale_y_continuous(breaks = seq(1
471,                     limits = c(0.5
472,  scale_color_manual(values = inf_colors3
473,  theme_minimal()+
474,  theme(
475,    plot.title = element_text(size = 10)   ) + 
476,scale_x_continuous(limits = c(55
477,
478,# Ensure the legend is positioned at the bottom
479,"p10g <- p10g + theme(legend.position = ""bottom"")"
480,
481,p14g <- ggplot(t14
482,  geom_point(size = 3) +
483," # geom_smooth(method = ""lm"""
484,"  labs(title = ""     14 C"""
485,"       x = """""
486,"       y = """") +"
487,  scale_y_continuous(breaks = seq(1
488,                     limits = c(0.5
489,  scale_color_manual(values = inf_colors3) +
490,  theme_minimal()+
491,  theme(
492,    plot.title = element_text(size = 10)   ) + 
493,scale_x_continuous(limits = c(55
494,
495,p18g <- ggplot(t18
496,  geom_point(size = 3) +
497,"  #geom_smooth(method = ""lm"""
498,"  labs(title = ""     18 C"""
499,"       x = """""
500,"       y = "" Condition "") +"
501,  scale_y_continuous(breaks = seq(1
502,                     limits = c(0.5
503,  scale_color_manual(values = inf_colors3) +
504,  theme_minimal()+
505,  theme(
506,    plot.title = element_text(size = 10)   ) + 
507,scale_x_continuous(limits = c(55
508,
509,p22g <- ggplot(t22
510,  geom_point(size = 3) +
511,"  #geom_smooth(method = ""lm"""
512,"  labs(title = ""     22 C"""
513,"       x = """""
514,"       y = """") +"
515,  scale_y_continuous(breaks = seq(1
516,                     limits = c(0.5
517,  scale_color_manual(values = inf_colors3) +
518,  theme_minimal()+
519,  theme(
520,    plot.title = element_text(size = 10)   ) + 
521,scale_x_continuous(limits = c(55
522,
523,p26g <- ggplot(t26
524,  geom_point(size = 4) +
525," # geom_smooth(method = ""lm"""
526,"  labs(title = ""b.   26 C"""
527,"       x = """""
528,"       y = """") +"
529,  scale_y_continuous(breaks = seq(1
530,                     limits = c(0.5
531,  scale_color_manual(values = inf_colors3) +
532,  theme_minimal()+
533,  theme(
534,    plot.title = element_text(size = 10)   ) + 
535,scale_x_continuous(limits = c(55
536,
537,# Increase font size 
538,custom_theme <- theme(
539,  axis.title = element_text(size = 14)
540,  axis.text = element_text(size = 12)
541,  legend.text = element_text(size = 12)
542,  legend.title = element_text(size = 12)
543,  plot.title = element_text(size = 12)
544,  strip.text = element_text(size = 14)       
545,)
546,
547,# Apply the custom theme to each plot
548,"CI2all <- CI2all + theme(legend.position = ""none"") + custom_theme"
549,"p10g <- p10g + theme(legend.position = ""bottom"") + custom_theme"
550,"p14g <- p14g + theme(legend.position = ""none"") + custom_theme"
551,"p18g <- p18g + theme(legend.position = ""none"") + custom_theme"
552,"p22g <- p22g + theme(legend.position = ""none"") + custom_theme"
553,"p26g <- p26g + theme(legend.position = ""none"") + custom_theme"
554,
555,# Define the layout for reproall and other plots
556,CI2all_layout <- ggarrange(CI2all
557,
558,other_plots <- ggarrange(p26g
559,                         ncol = 1
560,
561,# Combine reproall and other plots
562,grouped_plot <- ggarrange(CI2all_layout
563,                          widths = c(1
564,                          common.legend = TRUE
565,
566,# Display the grouped plot
567,print(grouped_plot)
568,"ggsave(""condition0706final.tiff"""
569,
570,#reproduction figure:
571,t10<- subset(as
572,t14<- subset(as
573,t18<- subset(as
574,t22<- subset(as
575,t26<- subset(as
576,
577,# Repro flipped:
578,reproall <- ggplot(as
579,  geom_boxplot() +
580,  coord_flip() +  # To flip the x and y axes
581,  scale_y_continuous(breaks = seq(0
582,                     limits = c(0
583,"  ggtitle(""a."") +"
584,"  xlab(""Temperature ( C)"") +  # Add x-axis label"
585,"  ylab(""Reproduction index"") +   # Add y-axis label"
586,  scale_fill_manual(values = inf_colors3)
587,
588,reproall
589,
590,#alternative as a dot plot:
591,
592,library(dplyr)
593,
594,# count observations
595,as_summary <- as %>%
596,  group_by(temp
597,  summarise(count = n()) %>%
598,  ungroup()
599,
600,reproall <- ggplot(as_summary
601,  geom_point(shape = 21
602,             position = position_dodge(width = 0.5)) +  
603,  coord_flip() +  # To flip the x and y axes
604,  scale_y_continuous(breaks = seq(0
605,"  ggtitle(""a."") +"
606,"  xlab(""Temperature ( C)"") +  "
607,"  ylab(""Reproduction index"") +   "
608,  scale_fill_manual(values = inf_colors3) +  
609,  scale_size_continuous(range = c(2
610,  theme_minimal()  
611,
612,# Display the plot
613,print(reproall)
614,
615,"new_legend_labels <- c(expression(""Control"")"
616,
617,# Create p10g plot with new legend labels
618,p10g <- ggplot(t10
619,  geom_point(position = position_jitter(width = 2
620,"  labs(title = ""     10 C"""
621,"       x = ""Days"""
622,"       y = """") +"
623,  scale_y_continuous(breaks = seq(0
624,                     limits = c(-0.5
625,  scale_color_manual(values = inf_colors3
626,  theme_minimal() +
627,  theme(
628,    plot.title = element_text(size = 10)
629,  ) + 
630,  scale_x_continuous(limits = c(55
631,
632,# Ensure the legend is positioned at the bottom
633,"p10g <- p10g + theme(legend.position = ""bottom"")"
634,
635,p14g <- ggplot(t14
636,  geom_point(position = position_jitter(width = 2
637,"  labs(title = ""     14 C"""
638,"       x = """""
639,"       y = """") +"
640,  scale_y_continuous(breaks = seq(0
641,                     limits = c(-0.5
642,  scale_color_manual(values = inf_colors3) +
643,  theme_minimal()+
644,  theme(
645,    plot.title = element_text(size = 10)   ) + 
646,  scale_x_continuous(limits = c(55
647,
648,p18g <- ggplot(t18
649,  geom_point(position = position_jitter(width = 2
650,"  labs(title = ""     18 C"""
651,"       x = """""
652,"       y = ""Reproduction"") +"
653,  scale_y_continuous(breaks = seq(0
654,                     limits = c(-0.5
655,  scale_color_manual(values = inf_colors3) +
656,  theme_minimal()+
657,  theme(
658,    plot.title = element_text(size = 10)   ) + 
659,  scale_x_continuous(limits = c(55
660,
661,p22g <- ggplot(t22
662,  geom_point(position = position_jitter(width = 2
663,"  labs(title = ""     22 C"""
664,"       x = """""
665,"       y = """") +"
666,  scale_y_continuous(breaks = seq(0
667,                     limits = c(-0.5
668,  scale_color_manual(values = inf_colors3) +
669,  theme_minimal()+
670,  theme(
671,    plot.title = element_text(size = 10)   ) + 
672,  scale_x_continuous(limits = c(55
673,
674,p26g <- ggplot(t26
675,  geom_point(position = position_jitter(width = 2
676,"  # geom_smooth(method = ""lm"""
677,"  labs(title = ""b.   26 C"""
678,"       x = """""
679,"       y = """") +"
680,  scale_y_continuous(breaks = seq(0
681,                     limits = c(-0.5
682,  scale_color_manual(values = inf_colors3) +
683,  theme_minimal()+
684,  theme(
685,    plot.title = element_text(size = 10)   ) + 
686,  scale_x_continuous(limits = c(55
687,
688,# Increase font size 
689,custom_theme <- theme(
690,  axis.title = element_text(size = 14)
691,  axis.text = element_text(size = 12)
692,  legend.text = element_text(size = 12)
693,  legend.title = element_text(size = 12)
694,  plot.title = element_text(size = 12)
695,  strip.text = element_text(size = 14)       
696,)
697,
698,"reproall <- reproall + theme(legend.position = ""none"")+ custom_theme"
699,"p10g <- p10g + theme(legend.position = ""bottom"")+ custom_theme "
700,"p14g <- p14g + theme(legend.position = ""none"")+ custom_theme"
701,"p18g <- p18g + theme(legend.position = ""none"")+ custom_theme"
702,"p22g <- p22g + theme(legend.position = ""none"")+ custom_theme"
703,"p26g <- p26g + theme(legend.position = ""none"")+ custom_theme"
704,
705,# Define the layout for reproall and other plots
706,reproall_layout <- ggarrange(reproall
707,
708,other_plots <- ggarrange(p26g
709,                         ncol = 1
710,
711,# Combine reproall and other plots
712,grouped_plot <- ggarrange(reproall_layout
713,                          widths = c(1
714,                          common.legend = TRUE
715,
716,# Display the grouped plot
717,print(grouped_plot)
718,"ggsave(""repro706final.tiff"""
719,
720,#supplementary figure 1 parasite number
721,"inf_colors <- c(""2"" = ""blue"""
722,as$inf<-as.numeric(as$inf)
723,as_filtered<-subset(as
724,
725,"inf_colors3 <- c(""0"" = ""green"""
726,
727,as_filtered$inf<-as.factor(as_filtered$inf)
728,"inf_colors <- c(""2"" = ""blue"""
729,
730,
731,# Create the boxplot with counts
732,palladults<-ggplot(as_filtered
733,  geom_boxplot() +
734,  scale_y_continuous(breaks = seq(0
735,                     limits = c(0
736,"  ggtitle(""Parasite load by temperature"")+"
737,"  xlab(""Temperature ( C)"") +  # Add x-axis label"
738,"  ylab(""Parasite number"")     +   # Add y-axis label"
739,  scale_fill_manual(values = inf_colors) 
740,
741,palladults
742,#separate plots for different temps over time:
743,t10<- subset(as_filtered
744,t14<- subset(as_filtered
745,t18<- subset(as_filtered
746,t22<- subset(as_filtered
747,t26<- subset(as_filtered
748,
749,#juveniles included:
750,p10<- ggplot(t10
751,  geom_point(size = 5) +  # Set the size to your preferred value
752,"  labs(title = ""Parasite load at 10 C"""
753,"       x = ""Days"""
754,"       y = ""Parasite number"") +"
755,  scale_y_continuous(breaks = seq(0
756,                     limits = c(0
757,  scale_color_manual(values = inf_colors) +
758,  theme_minimal()
759,p14<- ggplot(t14
760,  geom_point(size = 5) +  # Set the size to your preferred value
761,"  labs(title = ""Parasite load at 14 C"""
762,"       x = ""Days"""
763,"       y = ""Parasite number"") +"
764,  scale_y_continuous(breaks = seq(0
765,                     limits = c(0
766,  scale_color_manual(values = inf_colors) +
767,  theme_minimal()
768,p18<- ggplot(t18
769,  geom_point(size = 5) +  # Set the size to your preferred value
770,"  labs(title = ""Parasite load at 18 C"""
771,"       x = ""Days"""
772,"       y = ""Parasite number"") +"
773,  scale_y_continuous(breaks = seq(0
774,                     limits = c(0
775,  scale_color_manual(values = inf_colors) +
776,  theme_minimal()
777,p22<- ggplot(t22
778,  geom_point(size = 5) +  # Set the size to your preferred value
779,"  labs(title = ""Parasite load at 22 C"""
780,"       x = ""Days"""
781,"       y = ""Parasite number"") +"
782,  scale_y_continuous(breaks = seq(0
783,                     limits = c(0
784,  scale_color_manual(values = inf_colors) +
785,  theme_minimal()
786,p26<- ggplot(t26
787,  geom_point(size = 5) +  # Set the size to your preferred value
788,"  labs(title = ""Parasite load at 26 C"""
789,"       x = ""Days"""
790,"       y = ""Parasite number"") +"
791,  scale_y_continuous(breaks = seq(0
792,                     limits = c(0
793,  scale_color_manual(values = inf_colors) +
794,  theme_minimal()
795,
796,# Set the new legend labels
797,"#new_legend_labels <- c(""Mytilicola orientalis"""
798,"new_legend_labels <- c(expression(italic(""M. orientalis""))"
799,
800,palladults <- palladults + scale_fill_manual(values = inf_colors
801,ggarrange(palladults
802,         ncol = 2
803,
804,
805,#Means and 95% confidence intervals for growth:
806,
807,as$gtime<-as$growth / as$days
808,
809,gor<-subset(as
810,gint<-subset(as
811,gcon<-subset(as
812,
813,summary(gor$growth)
814,summary(gcon$growth)
815,summary(gint$growth)
816,
817,summary(gor$gtime)
818,summary(gcon$gtime)
819,summary(gint$gtime)
820,
821,gtime <- as$gtime
822,
823,#all:
824,mean_gtime <- mean(as$gtime)
825,ci <- t.test(as$gtime)$conf.int
826,"print(paste(""Mean:"""
827,"print(paste(""95% Confidence Interval:"""
828,
829,#controls:
830,mean_gtime <- mean(gcon$gtime)
831,ci <- t.test(gcon$gtime)$conf.int
832,"print(paste(""Mean:"""
833,"print(paste(""95% Confidence Interval:"""
834,
835,# ori:
836,mean_gtime <- mean(gor$gtime)
837,ci <- t.test(gor$gtime)$conf.int
838,"print(paste(""Mean:"""
839,"print(paste(""95% Confidence Interval:"""
840,
841,#int:
842,mean_gtime <- mean(gint$gtime)
843,ci <- t.test(gint$gtime)$conf.int
844,"print(paste(""Mean:"""
845,"print(paste(""95% Confidence Interval:"""
846,
847,
848,
849,#checking for possible bias in the condition values by mussel size:
850,plot(asr$end_length
851,cor_test_result <- cor.test(asr$end_length
852,print(cor_test_result)
