-1

I have a dataframe:

gene_symbol <- c("sads", "sdsds", "sdasdad", "dfds", "sdsdd")
panel <- c("big", "big", "big", "gr", "sm")
variable <- c("x", "x", "y", "z", "y")
value <- c("normal", "over", "low", "normal", "low")
colors <- c("red", "green", "yellow", "red", "red")

HG44 <- data.frame(gene_symbol, panel, variable, value, colors)
HG44$gene_symbol <- factor(HG44$gene_symbol, levels = unique(HG44$gene_symbol))

and I create a heatmap with:

library(ggplot2)
library(reshape2)

pp <- ggplot(HG44, aes(gene_symbol, variable)) + 
  geom_tile(aes(fill = value)) + 
  theme(axis.text.x = element_text(family = "Calibri", 
                                   size = 11, angle = 45, hjust = 1))

library(plotly)

ggplotly(pp)

As you can see the first 3 gene symbols belong to the panel "big" and the other 2 to the other 2 panel respectively. I would like somehow to separate those grouped gene symbols without using facet.grid(). I am thinking of adding an empty black column in the end of every group which will separate them from the others and will have the name of each panel at the top or at the bottom.

Adela
  • 1,757
  • 19
  • 37
firmo23
  • 7,490
  • 2
  • 38
  • 114
  • 1
    *"the first 3 gene symbols belong to the panel "big" and the other 2 to the other 2 panel respectively"* I don't see a panel named "big", nor do I see *any* panels. It's not clear to me what you're trying to do. Can you provide a mock-up of your expected output plot? – Maurits Evers Jul 28 '18 at 11:51
  • Also, what does `plotly` has to do with your question? – pogibas Jul 28 '18 at 11:53
  • When you plot the heatmap you see that "sads","dfds" and"sdsdd" are displayed first and they belong to the panel type "big". I delelted library(plotly). It was thereby mistake. – firmo23 Jul 28 '18 at 11:54
  • 1
    What you're asking is exactly what faceting does, why you don't want to use it? – pogibas Jul 28 '18 at 11:58
  • I re edited in order to show that the first 3 genes belong to "big". Faceting does not respond well with ggplotly() as I cannot set the column width. I have already asked this question https://stackoverflow.com/questions/51444351/how-to-make-the-column-widths-of-a-grouped-heatmap-all-the-same-in-ggplotly – firmo23 Jul 28 '18 at 12:04
  • I guess that `fill = panel` instead of `fill = value`? – Adela Aug 29 '18 at 11:02

1 Answers1

1

It seems you can use geom_vline function to separate these groups. See as below:

gene_symbol <- c("sads", "sdsds", "sdasdad","dfds","sdsdd")
panel <- c("big", "big", "big", "gr", "sm")
variable <- c("x","x","y","z","y")
value <- c("normal", "over", "low", "normal", "low")
colors <- c("red", "green", "yellow", "red", "red")

HG44 <- data.frame(gene_symbol, panel, variable, value, colors)
HG44$gene_symbol <- factor(HG44$gene_symbol, levels = unique(HG44$gene_symbol))

library(ggplot2)
library(reshape2)

pp <- ggplot(HG44, aes(gene_symbol,variable)) + 
  geom_tile(aes(fill = value)) + 
  theme(axis.text.x = element_text(family = "Calibri", size = 11, angle = 45, hjust = 1)) +
  geom_vline(xintercept = c(3.5, 4.5), size = 2)

library(plotly)
ggplotly(pp)

Output: Genes separated

Artem
  • 3,304
  • 3
  • 18
  • 41