-
Notifications
You must be signed in to change notification settings - Fork 1
/
barplot_anova.R
53 lines (43 loc) · 1.41 KB
/
barplot_anova.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
library(ggplot2)
library(cowplot)
library(dplyr)
library(magrittr)
# Load input
load(file.path("input.RData"))
# Remodel data
filtered_input_df <- filter(input_df, LOD != 0, !is.na(Group)) %>%
droplevels() %>%
group_by(Methods, Class, Tissue) %>%
dplyr::summarise(Number = length(grep("A", Group))) %>%
data.frame()
# Split across tissue types
df_list <- split(filtered_input_df, f = filtered_input_df$Tissue)
# Plot
plot_list <- lapply(df_list, function(x){
output <- ggplot(x, aes(x = Methods, y = Number, fill = Class)) +
geom_bar(stat = "identity") +
scale_fill_manual(values = col_vector) +
theme_light() +
theme(legend.position = "none", axis.text.x = element_text(angle = 45, hjust = 1, size = 8)) +
ggtitle(unique(x$Tissue)) +
ylim(c(0, 520)) +
xlab("")
return(output)
})
legend_plot <- ggplot(df_list$Liver, aes(x = Methods, y = Number, fill = Class)) +
geom_bar(stat = "identity") +
scale_fill_manual(values = col_vector) +
theme_light() +
ggtitle(unique(df_list$Liver$Tissue))
legend_graph <- get_legend(legend_plot)
# Combine plots
plot_grid(plot_grid(plot_list[[1]],
plot_list[[2]],
plot_list[[3]],
plot_list[[4]],
ncol = 2,
scale = 1),
plot_grid(legend_graph, scale = 0.3),
ncol = 2,
rel_widths = c(1, 0.7),
rel_heights = c(1, 0.5))