-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_log_length.r
51 lines (43 loc) · 1.65 KB
/
plot_log_length.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
library(ggplot2)
library(dplyr)
library(tidyr)
master_table <- read.csv("ptu_def_length.csv")
pcn_data <- master_table %>%
drop_na(NUCCORE_Length) %>%
filter(NUCCORE_Length > 0) %>%
mutate(
num_def_sys = ifelse(is.na(num_def_sys), 0, num_def_sys),
log10NUCCORE_Length = log10(NUCCORE_Length)
)
mean_log10NUCCORE_Length <- pcn_data %>%
group_by(`PTU_sHSBM_10`) %>%
summarise(median_log10NUCCORE_Length = median(log10NUCCORE_Length, na.rm = TRUE)) %>%
arrange(desc(median_log10NUCCORE_Length))
sorted_categories <- mean_log10NUCCORE_Length$`PTU_sHSBM_10`
pcn_data <- pcn_data %>%
mutate(PTU_sHSBM_10 = factor(PTU_sHSBM_10, levels = sorted_categories))
write.csv(pcn_data, "intermediate_data_for_log_plasmid_length_plot.csv", row.names = FALSE)
p <- ggplot() +
geom_boxplot(data = pcn_data,
aes(x = log10NUCCORE_Length, y = `PTU_sHSBM_10`),
width = 0.7,
fill = "lightblue",
color = "black",
outlier.size = 0.5) +
scale_x_continuous(
name = "log10 Plasmid Length"
) +
labs(
y = "PTU Classification",
title = "Boxplot of log10 Plasmid Length"
) +
theme_bw() +
theme(
axis.title.x = element_text(size = 12, face = "bold"),
axis.text.x = element_text(size = 10, face = "bold"),
axis.title.y = element_text(size = 12, face = "bold"),
axis.text.y = element_text(size = 10, face = "bold"),
plot.title = element_text(hjust = 0.5, size = 14, face = "bold")
) +
scale_y_discrete(limits = rev(levels(pcn_data$PTU_sHSBM_10)))
ggsave("Results/PTU_Group/log_plasmid_length.pdf", p, width = 6, height = 80, units = "in", dpi = 300, limitsize = FALSE)