load("C:/project/AMS_lely/AMS_Lely/ams_lely/20191008.RData")
library(ggplot2)
for(i in unique(dt_2_100$farm_id_1)){
x0 <- as.data.frame(prop.table(table(dt_2_100$mean_scc_diff_0[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]),2)); x0$day <- 0
x1 <- as.data.frame(prop.table(table(dt_2_100$mean_scc_diff_1[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]),2)); x1$day <- 1
x2 <- as.data.frame(prop.table(table(dt_2_100$mean_scc_diff_2[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]),2)); x2$day <- 2
x3 <- as.data.frame(prop.table(table(dt_2_100$mean_scc_diff_3[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]),2)); x3$day <- 3
x4 <- as.data.frame(prop.table(table(dt_2_100$mean_scc_diff_4[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]),2)); x4$day <- 4
x5 <- as.data.frame(prop.table(table(dt_2_100$mean_scc_diff_5[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]),2)); x5$day <- 5
x6 <- as.data.frame(prop.table(table(dt_2_100$mean_scc_diff_6[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]),2)); x6$day <- 6
x7 <- as.data.frame(prop.table(table(dt_2_100$mean_scc_diff_7[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]),2)); x7$day <- 7
x100 <- rbind(x0,x1,x2,x3,x4,x5,x6,x7)
names(x100) <- c("Differences", "Exposure", "value", "day")
x100$Exposure <- ifelse(x100$Exposure%in%c("exposure","Yes"), "Yes", "No")
x100$Differences <- factor(x100$Differences, levels =c("low", "high"))
x100$farm_id <- i
p <- ggplot(x100, aes(Exposure,value, fill= Differences)) + geom_bar(stat="identity", width = 0.7) +
facet_grid(.~day)+
scale_fill_manual(values = c("steelblue", "red")) +labs(title = i)
print(p)
print(i);print(0); print(table(dt_2_100$mean_scc_diff_0[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]))
print(i);print(1); print(table(dt_2_100$mean_scc_diff_1[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]))
print(i); print(2); print(table(dt_2_100$mean_scc_diff_2[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]))
print(i); print(3);print(table(dt_2_100$mean_scc_diff_3[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]))
print(i); print(4); print(table(dt_2_100$mean_scc_diff_4[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]))
print(i);print(5); print(table(dt_2_100$mean_scc_diff_5[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]))
print(i); print(6); print(table(dt_2_100$mean_scc_diff_6[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]))
print(i); print(7); print(table(dt_2_100$mean_scc_diff_7[which(dt_2_100$farm_id_1==i)],
dt_2_100$total_exposure_per_day_binary[which(dt_2_100$farm_id_1==i)]))
}

## [1] "DE_01"
## [1] 0
##
## exposure no exposure
## low 24 87
## [1] "DE_01"
## [1] 1
##
## exposure no exposure
## high 1 20
## low 23 67
## [1] "DE_01"
## [1] 2
##
## exposure no exposure
## high 3 19
## low 21 68
## [1] "DE_01"
## [1] 3
##
## exposure no exposure
## high 4 24
## low 20 63
## [1] "DE_01"
## [1] 4
##
## exposure no exposure
## high 3 22
## low 21 65
## [1] "DE_01"
## [1] 5
##
## exposure no exposure
## high 3 32
## low 21 55
## [1] "DE_01"
## [1] 6
##
## exposure no exposure
## high 5 30
## low 19 57
## [1] "DE_01"
## [1] 7
##
## exposure no exposure
## high 3 28
## low 21 59

## [1] "DE_02"
## [1] 0
##
## no exposure
## low 2
## [1] "DE_02"
## [1] 1
##
## no exposure
## high 1
## low 1
## [1] "DE_02"
## [1] 2
##
## no exposure
## high 2
## [1] "DE_02"
## [1] 3
##
## no exposure
## high 2
## [1] "DE_02"
## [1] 4
##
## no exposure
## high 1
## low 1
## [1] "DE_02"
## [1] 5
##
## no exposure
## high 1
## low 1
## [1] "DE_02"
## [1] 6
##
## no exposure
## high 1
## low 1
## [1] "DE_02"
## [1] 7
##
## no exposure
## high 1
## low 1

## [1] "DE_04"
## [1] 0
##
## exposure no exposure
## low 2 17
## [1] "DE_04"
## [1] 1
##
## exposure no exposure
## high 0 10
## low 2 7
## [1] "DE_04"
## [1] 2
##
## exposure no exposure
## high 2 13
## low 0 4
## [1] "DE_04"
## [1] 3
##
## exposure no exposure
## high 2 15
## low 0 2
## [1] "DE_04"
## [1] 4
##
## exposure no exposure
## high 1 10
## low 1 7
## [1] "DE_04"
## [1] 5
##
## exposure no exposure
## high 1 10
## low 1 7
## [1] "DE_04"
## [1] 6
##
## exposure no exposure
## high 1 12
## low 1 5
## [1] "DE_04"
## [1] 7
##
## exposure no exposure
## high 1 10
## low 1 7

## [1] "DE_05"
## [1] 0
##
## no exposure
## low 2
## [1] "DE_05"
## [1] 1
##
## no exposure
## high 1
## low 1
## [1] "DE_05"
## [1] 2
##
## no exposure
## high 1
## low 1
## [1] "DE_05"
## [1] 3
##
## no exposure
## high 1
## low 1
## [1] "DE_05"
## [1] 4
##
## no exposure
## high 1
## low 1
## [1] "DE_05"
## [1] 5
##
## no exposure
## high 2
## [1] "DE_05"
## [1] 6
##
## no exposure
## high 2
## [1] "DE_05"
## [1] 7
##
## no exposure
## high 2

## [1] "DE_06"
## [1] 0
##
## exposure no exposure
## high 0 3
## low 721 4919
## [1] "DE_06"
## [1] 1
##
## exposure no exposure
## high 7 162
## low 714 4760
## [1] "DE_06"
## [1] 2
##
## exposure no exposure
## high 20 242
## low 701 4680
## [1] "DE_06"
## [1] 3
##
## exposure no exposure
## high 31 239
## low 690 4683
## [1] "DE_06"
## [1] 4
##
## exposure no exposure
## high 40 257
## low 681 4665
## [1] "DE_06"
## [1] 5
##
## exposure no exposure
## high 29 264
## low 692 4658
## [1] "DE_06"
## [1] 6
##
## exposure no exposure
## high 41 280
## low 680 4642
## [1] "DE_06"
## [1] 7
##
## exposure no exposure
## high 31 287
## low 690 4635