Unable to display minor grid lines in ggplot2

I am trying to differentiate the tiles by displaying white minor grid lines but I am unable to get it to work. Could someone help me please.

This is what my function looks like. I have tried changing the panel.grid.minor to specify x & y gridlines as well. Didnt work. Help please. Thanks in advance

library(ggplot2)
library(tidyverse)

# Read the data
data <- read.table("pd_output.txt", header = TRUE, sep = "\t")

# Create a generic waterfall plot function
create_waterfall_plot <- function(data) {
  data <- data %>%
    mutate(mutation_types = factor(mutation_types),
           variant_consequences = factor(variant_consequences),
           impact = factor(impact),
           clinical_annotations = factor(clinical_annotations),
           TE_fusion = factor(TE_fusion),
           hotspot = factor(hotspot))
  
  plot <- ggplot(data, aes(x = sampleID, y = gene_name)) +
    theme_bw() +
    theme(panel.grid.major = element_blank(),
          panel.grid.minor = element_line(size = 2, colour ="white"),
          axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) +
    geom_tile(aes(fill = variant_consequences, colour = mutation_types, alpha = 0.5), size = 0.5, width = 0.8, height = 0.8) +
    geom_point(aes(shape = mutation_types, colour = impact), size = 3) +
    scale_fill_manual(values = c("missense_variant" = "blue", "splice_donor_variant" = "orange", "stop_gained" = "darkgreen", "frameshift_variant" = "yellow", "inframe_deletion" = "brown", "missense_variant&splice_region_variant" = "violet", "stop_gained & inframe_deletion" = "gray", "inframe_insertion" = "cyan")) +
    scale_color_manual(values = c("MODERATE" = "lightpink", "HIGH" = "red")) +
    labs(x = "Sample ID", y = "Gene Name",
    fill = "Variant Consequences", colour = "Impact", shape = "CLONALITY") +
    
    guides(alpha = FALSE) 
    
  return(plot)
}

# Generate the waterfall plot
waterfall_plot <- create_waterfall_plot(data)
print(waterfall_plot)

Sample data looks like this

sampleID    gene_name   mutation_types  variant_consequences    impact  clinical_annotations    TE_fusion   hotspot
P-0028  NCOR1   CLONAL  missense_variant    MODERATE    localised   no  no
P-0029  SETD2   CLONAL  splice_donor_variant    HIGH    localised   yes yes
P-0030  ATM SUBCLONAL   stop_gained HIGH    localised   no  no
P-0031  CDKN1B  CLONAL  frameshift_variant  HIGH    localised   yes no
P-0032  KMT2C   CLONAL  stop_gained HIGH    metastatic  no  no
P-0033  FOXA1   CLONAL  stop_gained HIGH    metastatic  yes yes
P-0034  NCOR1   CLONAL  missense_variant    MODERATE    metastatic  yes no
P-0035  KMT2A   CLONAL  missense_variant    MODERATE    localised   yes no
P-0036  KMT2C   CLONAL  missense_variant    MODERATE    localised   yes no

current output plot looks like this



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation