library(stats)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.0.4     ✓ dplyr   1.0.2
## ✓ tidyr   1.1.2     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## Warning: package 'ggplot2' was built under R version 4.0.2
## Warning: package 'tibble' was built under R version 4.0.2
## Warning: package 'tidyr' was built under R version 4.0.2
## Warning: package 'dplyr' was built under R version 4.0.2
## Warning: package 'forcats' was built under R version 4.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(haven)

herd <- read_dta("Herd.dta")

herd$bedtype <- as.factor(herd$Bedtype)
?facet_grid

Used bedding

Used bedding. Staph vs Coliform counts

ggplot(herd, aes(x=logUbedSta, y=logUbedCol, colour=bedtype, group=bedtype)) + 
  geom_point(size=3, shape=21, fill="white") + # 21 is filled circle
  theme_bw() + theme(panel.border = element_rect(colour = "black", fill=NA,size=1),axis.text=element_text(size=12,family="Times"),axis.title=element_text(size=14,face="bold",family="Times"),panel.background = element_rect(fill = "white", colour = "white",size = 0.5, linetype = "solid"),panel.grid.major = element_line(size = 0.5, linetype = 'solid', colour = "grey"), panel.grid.minor = element_line(size = 0.25, linetype = 'solid',colour = "grey"),legend.position="bottom",legend.text = element_text(colour="black", size=12,face="bold",family="Times")) + scale_color_brewer(palette="Set1") +
  facet_grid( ~ factor(bedtype))

cor.test(herd$logUbedSta,herd$logUbedCol)
## 
##  Pearson's product-moment correlation
## 
## data:  herd$logUbedSta and herd$logUbedCol
## t = 1.5148, df = 148, p-value = 0.1319
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.03743845  0.27831462
## sample estimates:
##       cor 
## 0.1235645

The diagram above shows 4 scatter plots where the X-axis is Staph counts in bedding and the Y-axis is Coliform counts. The plots have been stratified by bedding type. Bedtype code guide below:

0 = Manure solids

1 = New Sand

2 = Other organic

3 = Reclaimed sand

Used bedding. Staph vs Strep counts

ggplot(herd, aes(x=logUbedSta, y=logUbedEnv, colour=bedtype, group=bedtype)) + 
  geom_point(size=3, shape=21, fill="white") + # 21 is filled circle
  theme_bw() + theme(panel.border = element_rect(colour = "black", fill=NA,size=1),axis.text=element_text(size=12,family="Times"),axis.title=element_text(size=14,face="bold",family="Times"),panel.background = element_rect(fill = "white", colour = "white",size = 0.5, linetype = "solid"),panel.grid.major = element_line(size = 0.5, linetype = 'solid', colour = "grey"), panel.grid.minor = element_line(size = 0.25, linetype = 'solid',colour = "grey"),legend.position="bottom",legend.text = element_text(colour="black", size=12,face="bold",family="Times")) + scale_color_brewer(palette="Set1") +
  facet_grid( ~ factor(bedtype))

cor.test(herd$logUbedSta,herd$logUbedEnv)
## 
##  Pearson's product-moment correlation
## 
## data:  herd$logUbedSta and herd$logUbedEnv
## t = 1.1347, df = 148, p-value = 0.2583
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.06840734  0.24942153
## sample estimates:
##        cor 
## 0.09287236

Used bedding. Staph vs Total count

ggplot(herd, aes(x=logUbedSta, y=logUbedTBC, colour=bedtype, group=bedtype)) + 
  geom_point(size=3, shape=21, fill="white") + # 21 is filled circle
  theme_bw() + theme(panel.border = element_rect(colour = "black", fill=NA,size=1),axis.text=element_text(size=12,family="Times"),axis.title=element_text(size=14,face="bold",family="Times"),panel.background = element_rect(fill = "white", colour = "white",size = 0.5, linetype = "solid"),panel.grid.major = element_line(size = 0.5, linetype = 'solid', colour = "grey"), panel.grid.minor = element_line(size = 0.25, linetype = 'solid',colour = "grey"),legend.position="bottom",legend.text = element_text(colour="black", size=12,face="bold",family="Times")) + scale_color_brewer(palette="Set1") +
  facet_grid( ~ factor(bedtype))

cor.test(herd$logUbedSta,herd$logUbedTBC)
## 
##  Pearson's product-moment correlation
## 
## data:  herd$logUbedSta and herd$logUbedTBC
## t = -0.0124, df = 148, p-value = 0.9901
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1612544  0.1592683
## sample estimates:
##          cor 
## -0.001019255

New bedding

New bedding. Staph vs Coliform counts

ggplot(herd, aes(x=logNbedSta, y=logNbedCol, colour=bedtype, group=bedtype)) + 
  geom_point(size=3, shape=21, fill="white") + # 21 is filled circle
  theme_bw() + theme(panel.border = element_rect(colour = "black", fill=NA,size=1),axis.text=element_text(size=12,family="Times"),axis.title=element_text(size=14,face="bold",family="Times"),panel.background = element_rect(fill = "white", colour = "white",size = 0.5, linetype = "solid"),panel.grid.major = element_line(size = 0.5, linetype = 'solid', colour = "grey"), panel.grid.minor = element_line(size = 0.25, linetype = 'solid',colour = "grey"),legend.position="bottom",legend.text = element_text(colour="black", size=12,face="bold",family="Times")) + scale_color_brewer(palette="Set1") +
  facet_grid( ~ factor(bedtype))
## Warning: Removed 2 rows containing missing values (geom_point).

cor.test(herd$logNbedSta,herd$logNbedCol)
## 
##  Pearson's product-moment correlation
## 
## data:  herd$logNbedSta and herd$logNbedCol
## t = 1.4228, df = 146, p-value = 0.1569
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.04525185  0.27313600
## sample estimates:
##       cor 
## 0.1169458

New bedding. Staph vs Strep counts

ggplot(herd, aes(x=logNbedSta, y=logNbedEnv, colour=bedtype, group=bedtype)) + 
  geom_point(size=3, shape=21, fill="white") + # 21 is filled circle
  theme_bw() + theme(panel.border = element_rect(colour = "black", fill=NA,size=1),axis.text=element_text(size=12,family="Times"),axis.title=element_text(size=14,face="bold",family="Times"),panel.background = element_rect(fill = "white", colour = "white",size = 0.5, linetype = "solid"),panel.grid.major = element_line(size = 0.5, linetype = 'solid', colour = "grey"), panel.grid.minor = element_line(size = 0.25, linetype = 'solid',colour = "grey"),legend.position="bottom",legend.text = element_text(colour="black", size=12,face="bold",family="Times")) + scale_color_brewer(palette="Set1") +
  facet_grid( ~ factor(bedtype))
## Warning: Removed 2 rows containing missing values (geom_point).

cor.test(herd$logNbedSta,herd$logNbedEnv)
## 
##  Pearson's product-moment correlation
## 
## data:  herd$logNbedSta and herd$logNbedEnv
## t = 3.9854, df = 146, p-value = 0.000106
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1599749 0.4517472
## sample estimates:
##       cor 
## 0.3132339

New bedding. Staph vs Total count

ggplot(herd, aes(x=logNbedSta, y=logNbedTBC, colour=bedtype, group=bedtype)) + 
  geom_point(size=3, shape=21, fill="white") + # 21 is filled circle
  theme_bw() + theme(panel.border = element_rect(colour = "black", fill=NA,size=1),axis.text=element_text(size=12,family="Times"),axis.title=element_text(size=14,face="bold",family="Times"),panel.background = element_rect(fill = "white", colour = "white",size = 0.5, linetype = "solid"),panel.grid.major = element_line(size = 0.5, linetype = 'solid', colour = "grey"), panel.grid.minor = element_line(size = 0.25, linetype = 'solid',colour = "grey"),legend.position="bottom",legend.text = element_text(colour="black", size=12,face="bold",family="Times")) + scale_color_brewer(palette="Set1") +
  facet_grid( ~ factor(bedtype))
## Warning: Removed 2 rows containing missing values (geom_point).

cor.test(herd$logNbedSta,herd$logNbedTBC)
## 
##  Pearson's product-moment correlation
## 
## data:  herd$logNbedSta and herd$logNbedTBC
## t = 5.3702, df = 146, p-value = 3.031e-07
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.2619605 0.5325834
## sample estimates:
##       cor 
## 0.4061386