library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.5.2
library(tidyr)
## Warning: package 'tidyr' was built under R version 3.5.2
library(reshape2)
## Warning: package 'reshape2' was built under R version 3.5.2
## 
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
## 
##     smiths
library(gridExtra)
## Warning: package 'gridExtra' was built under R version 3.5.2
library(grid)
library(cowplot)
## Warning: package 'cowplot' was built under R version 3.5.2
## 
## Attaching package: 'cowplot'
## The following object is masked from 'package:ggplot2':
## 
##     ggsave
library(forcats)
## Warning: package 'forcats' was built under R version 3.5.2
## Barplot for psi
p = read.csv("common_psi.csv", header=TRUE, sep=,)
p$idx = row.names(p)
bar.psi = ggplot(p, aes(x=idx, y=psi)) + coord_flip() + geom_bar(stat="identity") + theme(axis.text.y = element_blank(), axis.title.y = element_blank(), axis.ticks.y = element_blank(), axis.title.x = element_blank()) + ggtitle( "PSI")

## Heatmap for Splicing events
sp = read.csv("common_splicing.csv", header=TRUE, sep=,)
df.sp = sp %>% gather(sample, value, -GeneName)
df.sp$idx = rep(c(1:137), 12)

hm.sp = ggplot(df.sp, aes(x = sample, y = fct_reorder(GeneName, idx, .desc = TRUE), fill = value)) + geom_tile() + scale_fill_gradient(low = "blue", high = "red") + theme(legend.title = element_text(size = 10), legend.text = element_text(size = 8), plot.title = element_text(size = 14), axis.ticks.y = element_blank(), axis.text.y = element_text(size = 8, hjust = 0.5), axis.title.x = element_blank(), axis.title.y = element_blank()) + labs(fill = "psi%") + ggtitle( "Splicing Events")

tmp = ggplot_gtable(ggplot_build(hm.sp))
leg = which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
legend.sp = tmp$grobs[[leg]]

hm.sp.no.legend = hm.sp + theme(legend.position = "none")

## Heatmap for Gene Expressions
fpkm = read.csv("common_fpkm.csv", header=TRUE, sep=,)

df.fpkm = fpkm %>% gather(sample, value, -GeneName)

df.fpkm$idx = rep(c(1:137), 12)

hm.fpkm = ggplot(df.fpkm, aes(x = sample, y = fct_reorder(GeneName, idx, .desc = TRUE), fill = value)) + geom_tile() + scale_fill_gradient(low = "blue", high = "red") + theme(legend.title = element_text(size = 10), legend.text = element_text(size = 8), plot.title = element_text(size = 14), axis.ticks.y = element_blank(), axis.text.y = element_blank(), axis.title.x = element_blank(), axis.title.y = element_blank()) + labs(fill = "fpkm") + ggtitle( "Gene Expressions")

tmp = ggplot_gtable(ggplot_build(hm.fpkm))
leg = which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
legend.fpkm = tmp$grobs[[leg]]

hm.fpkm.no.legend = hm.fpkm + theme(legend.position = "none")

## grouping with Alternative Acceptor, Alternative Donor, Cassette
group = data.frame(GeneName = fpkm$GeneName, sample = c(rep("G", 137)), value = c(rep(10, 14), rep(50, 13), rep(100, 110)), idx = c(1:137))

bar.group = ggplot(group, aes(x = sample, y = fct_reorder(GeneName, idx, .desc = TRUE), fill = value)) + geom_tile() + scale_fill_gradient(low = "yellow", high = "green") + theme(axis.text.y = element_blank(), axis.ticks.y = element_blank(), axis.title.x = element_blank(), axis.title.y = element_blank(), axis.ticks.x = element_blank(), legend.position = "none") + ggtitle( "type")
## Grouping by Wild and Mutant
wi.mu = data.frame(GeneName = c("AAAAA"), sample = c(letters[1:12]), value = c(rep(0, 9), rep(100, 3)))

bar.wi.mu = ggplot(wi.mu, aes(x = sample, y = GeneName, fill = value)) + geom_tile() + scale_fill_gradient(low = "cornsilk", high = "lightseagreen") + theme(axis.text.y = element_blank(), axis.ticks.y = element_blank(), axis.title.x = element_blank(), axis.text.x = element_blank(), axis.title.y = element_blank(), axis.ticks.x = element_blank(), legend.position = "none")

bar.wi.mu.y = ggplot(wi.mu, aes(x = sample, y = GeneName, fill = value)) + geom_tile() + scale_fill_gradient(low = "cornsilk", high = "lightseagreen") + theme(axis.ticks.y = element_blank(), axis.title.y = element_blank(),  axis.ticks.x = element_blank(), axis.text.x = element_blank(), axis.title.x = element_blank(), legend.position = "none")


## Legend for Grouping
df.legend = data.frame(type = c("Alternative Acceptor", "Alternative Donor", "Cassette", "Wild", "Mutant"), len = c(1, 2, 3, 4, 5))

bar.legend = ggplot(df.legend, aes(x = type, y = len, fill = type)) + geom_bar(stat = "identity") + theme_minimal() + scale_fill_manual(values = c("yellow", "#B8FF00", "green", "cornsilk", "lightseagreen"))

tmp = ggplot_gtable(ggplot_build(bar.legend))
leg = which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
legend.bar = tmp$grobs[[leg]]

## Plot all together
grid.arrange(bar.group, hm.fpkm.no.legend, hm.sp.no.legend, bar.psi, legend.fpkm, legend.sp, legend.bar, bar.wi.mu, bar.wi.mu.y, layout_matrix = matrix(c(1,2,3,4,5,6,7,NA,8,9,NA,NA,NA,NA), nrow = 2, byrow=TRUE), widths = c(4, 40, 40, 10, 5, 5, 10), heights = c(60, 3))

Save as a pdf with 20*15 inch