#Data cleaning---- library(tidyverse) library(pheatmap) bean_fpkm <- read_table("fpkm_mean.txt") conditions <- read_csv("samples_description.csv") cladevb <- c("Phvul.001G112900", "Phvul.001G112800", "Phvul.003G143100", "Phvul.001G112500", "Phvul.001G112400", "Phvul.006G037000", "Phvul.002G025600", "Phvul.005G098300", "Phvul.005G097900", "Phvul.005G0986002", "Phvul.005G0988000") exp_cladevb <- bean_fpkm %>% dplyr::filter(gene %in% cladevb) hhht_all_tissues <- exp_cladevb %>% dplyr::filter(gene == "Phvul.006G037000") %>% dplyr::select(-gene) %>% pivot_longer(cols= everything(), names_to = "sample", values_to = "expression") hhht_all_tissues <- hhht_all_tissues %>% dplyr::left_join(conditions, by = "sample") matrix <- hhht_all_tissues %>% dplyr::select(-sample) %>% pivot_wider(names_from = name, values_from = expression) h <- as.matrix(matrix) #heatmap--- #Overwrite default draw_colnames in the pheatmap package. # Thanks to Josh O'Brien at http://stackoverflow.com/questions/15505607 draw_colnames_45 <- function (coln, gaps, ...) { coord <- pheatmap:::find_coordinates(length(coln), gaps) x <- coord$coord - 0.5 * coord$size res <- grid::textGrob( coln, x = x, y = unit(1, "npc") - unit(3,"bigpts"), vjust = 0.75, hjust = 1, rot = 60, gp = grid::gpar(...) ) return(res) } assignInNamespace( x = "draw_colnames", value = "draw_colnames_45", ns = asNamespace("pheatmap") ) #Colors ---- mypalette<- colorRampPalette(c("#FFFFFF","#6C9CBC","#4C91BD","#0768A7"))(n = 299) #Exporting image ---- cairo_ps("final_heatmap", width = 7.5, height = 5) pheatmap (h, main="hhht expression data", cellwidth=19, cellheight=17, display_numbers = TRUE, number_format = "%.1f", number_color = "black", border_color ="grey", #square edges color clustering_distance_cols="euclidean", treeheight_row=75, #dendogram height, default is 50 clustering_method="complete", cluster_cols=TRUE, cluster_rows=FALSE, fontsize=7.8, col = mypalette, margins=c(5,10)) dev.off()