How can I plot this data in R? I need to develop a heatmap out of this data

Here is my input file in csv 1.Q3L8U1,Pathway1 2.Q15788,Pathway1 3.P10415,Pathway1 4.P07900,Pathway2 5.P28066,Pathway2 6.P10415,Pathway2 7.Q8N726,Pathway3 8.P48454,Pathway3 9.P04637,Pathway3 10.Q14204,Pathway4 11.P10415,Pathway4 12.P10415,Pathway4 13.Q13114,Pathway5 14.P49662,Pathway6

I need to plot a heatmap of this data in R. I need to show the cluster of ids in each pathways.

1 answer

  • answered 2020-11-25 06:55 Turing

    Maybe you need to improve your question. You can find an example of heatmap here:

    # Libraries
    library(tidyverse)
    library(hrbrthemes)
    library(viridis)
    library(plotly)
    library(d3heatmap)
    
    # Load data 
    data <- read.table("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/multivariate.csv", header=T, sep=";")
    colnames(data) <- gsub("\\.", " ", colnames(data))
    
    # Select a few country
    data <- data %>% 
      filter(Country %in% c("France", "Sweden", "Italy", "Spain", "England", "Portugal", "Greece", "Peru", "Chile", "Brazil", "Argentina", "Bolivia", "Venezuela", "Australia", "New Zealand", "Fiji", "China", "India", "Thailand", "Afghanistan", "Bangladesh", "United States of America", "Canada", "Burundi", "Angola", "Kenya", "Togo")) %>%
      arrange(Country) %>%
      mutate(Country = factor(Country, Country))
    
    # Matrix format
    mat <- data
    rownames(mat) <- mat[,1]
    mat <- mat %>% dplyr::select(-Country, -Group, -Continent)
    mat <- as.matrix(mat)
    
    # Heatmap
    #d3heatmap(mat, scale="column", dendrogram = "none", width="800px", height="80Opx", colors = "Blues")
    
    library(heatmaply)
    p <- heatmaply(mat, 
            dendrogram = "none",
            xlab = "", ylab = "", 
            main = "",
            scale = "column",
            margins = c(60,100,40,20),
            grid_color = "white",
            grid_width = 0.00001,
            titleX = FALSE,
            hide_colorbar = TRUE,
            branches_lwd = 0.1,
            label_names = c("Country", "Feature:", "Value"),
            fontsize_row = 5, fontsize_col = 5,
            labCol = colnames(mat),
            labRow = rownames(mat),
            heatmap_layers = theme(axis.line=element_blank())
            )