Load libraries:
library(ggplot2)
library(dplyr)
library(rstatix)
data = data.frame(x1 = rep(c(1,2,3,4,5,6),4),
x2 = rep(c(2,3,4,5,6,7),4),
y1 = c(rep(1,6), rep(2,6), rep(3,6),rep(4,6)),
y2 = c(rep(2,6), rep(3,6), rep(4,6), rep(5,6)),
ctr = c("D1", "D2", "D3", "D4", "D5", "D6",
"C1", "C2", "C3", "C4", "C5", "C6",
"B1", "B2", "B3", "B4", "B5", "B6",
"A1", "A2", "A3", "A4", "A5", "A6"),
count = c("analysed", rep("not analysed", 4), "analysed",
rep("not analysed", 6),
rep("not analysed", 2), "analysed", rep("not analysed", 3),
"analysed", rep("not analysed", 4), "analysed"))
ggplot(data=data) +
geom_rect(mapping=aes(xmin=x1, xmax=x2, ymin=y1, ymax=y2, fill = count), color="black", alpha=0.5) +
geom_text(aes(x=x1+(x2-x1)/2, y=y1+(y2-y1)/2, label=ctr), size=4) +
scale_x_continuous(breaks = c(1.5, 2.5, 3.5, 4.5, 5.5, 6.5), labels = c(500, 700, 900, 1100, 1300, 1500)) +
scale_y_continuous(breaks = c(1.5, 2.5, 3.5, 4.5), labels = c(6, 5, 4, 3)) +
xlab("rpm") +
ylab("min")
Import the data:
data <- read.table("size_data.txt", header = T)
data$treatment <- factor(data$treatment, levels = c("L", "CC", "S"),
labels = c("large", "control", "small"))
# Calculate the average cell size by sample
mean_data <- data %>%
group_by(treatment, centrifugation) %>%
summarise(avg_size = mean(size), sd_size = sd(size), na.rm = T)
ggplot(data, aes(x = size, fill = treatment)) +
geom_density(alpha = 0.3) +
geom_vline(data = mean_data, aes(xintercept = avg_size, color = treatment),
linetype = "dashed", size = 1) +
xlab (expression(paste("Cell size (",mu,"m)", sep=""))) +
ylab("Density") +
facet_wrap(~ centrifugation)
ggplot(data, aes(x = size, fill = treatment)) +
geom_histogram(alpha = 0.7) +
xlab (expression(paste("Cell size (",mu,"m)", sep=""))) +
ylab("Count") +
facet_wrap(~ centrifugation)
ggplot(data, aes(x = size, y = centrifugation, fill = treatment, by = treatment)) +
geom_boxplot() +
theme(legend.position="top")
mean_data
## # A tibble: 13 x 5
## # Groups: treatment [3]
## treatment centrifugation avg_size sd_size na.rm
## <fct> <chr> <dbl> <dbl> <lgl>
## 1 large A1 4.13 0.468 TRUE
## 2 large A6 4.28 0.422 TRUE
## 3 large B3 4.16 0.388 TRUE
## 4 large D1 4.20 0.483 TRUE
## 5 large D6 4.35 0.441 TRUE
## 6 control A1 4.22 0.487 TRUE
## 7 control A6 4.27 0.567 TRUE
## 8 control D1 4.21 0.496 TRUE
## 9 small A1 3.85 0.568 TRUE
## 10 small A6 3.92 0.629 TRUE
## 11 small B3 3.73 0.749 TRUE
## 12 small D1 3.83 0.463 TRUE
## 13 small D6 3.66 0.684 TRUE
pwc <- data %>%
group_by(centrifugation) %>%
pairwise_t_test(size ~ treatment, p.adjust.method = "bonferroni")
pwc
## # A tibble: 11 x 10
## centrifugation .y. group1 group2 n1 n2 p p.signif p.adj
## * <chr> <chr> <chr> <chr> <int> <int> <dbl> <chr> <dbl>
## 1 A1 size large control 84 48 0.309 ns 9.27e-1
## 2 A1 size large small 84 60 0.00129 ** 3.86e-3
## 3 A1 size control small 48 60 0.000191 *** 5.72e-4
## 4 A6 size large control 65 48 0.987 ns 1 e+0
## 5 A6 size large small 65 68 0.000212 *** 6.37e-4
## 6 A6 size control small 48 68 0.000666 *** 2 e-3
## 7 B3 size large small 62 55 0.000138 *** 1.38e-4
## 8 D1 size large control 98 57 0.83 ns 1 e+0
## 9 D1 size large small 98 51 0.0000127 **** 3.8 e-5
## 10 D1 size control small 57 51 0.0000407 **** 1.22e-4
## 11 D6 size large small 58 28 0.000000222 **** 2.22e-7
## # ... with 1 more variable: p.adj.signif <chr>
data_small <- mean_data %>%
filter(treatment == "small")
data_large <- mean_data %>%
filter(treatment == "large")
data_control <- mean_data %>%
filter(treatment == "control")
data_small$diff <- (data_large$avg_size - data_small$avg_size)*100/data_large$avg_size
ggplot(data = data_small, aes(x = diff, y = centrifugation)) +
geom_point(size = 3) +
xlab("Differential selection (%)") +
ylab("Centrifugation effort") +
ggtitle("Large versus small") +
xlim(0,16)
cc_small <- data_small %>%
filter(centrifugation == "A1" | centrifugation == "A6" | centrifugation == "D1")
cc_large <- data_large %>%
filter(centrifugation == "A1" | centrifugation == "A6" | centrifugation == "D1")
cc_small$diff <- (data_control$avg_size - cc_small$avg_size)*100/data_control$avg_size
cc_large$diff <- (data_control$avg_size - cc_large$avg_size)*100/data_control$avg_size
ggplot(data = cc_small, aes(x = diff, y = centrifugation)) +
geom_point(size = 3) +
xlab("Differential selection (%)") +
ylab("Centrifugation effort") +
ggtitle("Control versus small") +
xlim(0,16)
ggplot(data = cc_large, aes(x = diff, y = centrifugation)) +
geom_point(size = 3) +
xlab("Differential selection (%)") +
ylab("Centrifugation effort") +
ggtitle("Control versus large") +
xlim(0,16)
data_count <- read.table("count_data.txt", header = T)
data_count$treatment <- factor(data_count$treatment, levels = c("L", "CC", "S"),
labels = c("large", "control", "small"))
ggplot(data_count, aes(x = cell_ml/10^5, y = centrifugation, color = treatment, by = treatment)) +
geom_point(size = 3) +
theme(legend.position="top") +
ylab("Centrifugation effort") +
xlab (expression(paste("Cells m",L^-1,"x ", 10^5, sep="")))
count_small <- data_count %>%
filter(treatment == "small")
count_large <- data_count %>%
filter(treatment == "large")
count_control <- data_count %>%
filter(treatment == "control")
count_small$diff <- (count_control$cell_ml - count_small$cell_ml)*100/count_control$cell_ml
count_large$diff <- (count_control$cell_ml - count_large$cell_ml)*100/count_control$cell_ml
ggplot(data = count_small, aes(x = diff, y = centrifugation)) +
geom_point(size = 3) +
xlab("Differential selection (%)") +
ylab("Centrifugation effort") +
ggtitle("Control versus small") +
xlim(0,100)
ggplot(data = count_large, aes(x = diff, y = centrifugation)) +
geom_point(size = 3) +
xlab("Differential selection (%)") +
ylab("Centrifugation effort") +
ggtitle("Control versus large") +
xlim(-500,100)
data_cn <- read.table("cn.txt", header = T)
ggplot(data_cn, aes(x = day, y = cell_ml, col = centrifugation)) +
geom_point(size = 3)