2

Hello I have the dataset below:

gene_symbol <- c("DADA", "SDAASD", "SADDSD", "SDADD")
panel <- c("growth", "growth", "big", "small")
ASDDA <- c("normal", "over", "low", "over")
ASDDb <- c("normal", "over", "low", "over")
ASDDAf <- c("normal", "over", "low", "over")
Gene_states22 <- data.frame(gene_symbol, panel, ASDDA, ASDDb, ASDDAf)

What I want to achieve besides creating a heatmap with:

library(plotly)
library(ggplot2); library(reshape2)
g <- melt(Gene_states22, id.vars = c("gene_symbol","panel"))
p1 <- ggplot(g, aes(gene_symbol,variable)) + 
  geom_tile(aes(fill = value), colour = "grey50") +
  scale_fill_manual(values=c("white", "red", "blue"))+
  labs(title = "Heatmap",x = "gene_symbol",y="sample",fill="value")+
  theme(title = element_text(family = "sans serif", 
                             size = 14, 
                             face = "bold"), 
        axis.title = element_text(family = "sans serif", 
                                  size = 16, 
                                  face = "bold", 
                                  color = "black"), 
        axis.text = element_text(family = "sans serif", 
                                 size = 11),
        axis.title.y = element_text(margin = margin(t = 0, r = 25, b = 0, l = 25)),
        panel.background = element_rect(fill = NA),
        panel.grid.major = element_line(colour = "grey50"))
p1
ggplotly(p1)%>%
  layout(autosize = F, 
         width = 1450, 
         height = 600,
         hoverlabel = list(bgcolor = "white",
                           font = list(family = "sans serif", 
                                       size = 9, 
                                       color = "black")))

is group my values according to panel. For example: enter image description here

here there is a second x-axis which groups the values by "Mechanical","Electrical","Hydraylic". I want to do the same with the panel. Note that the graph should be interactive and this is why I use ggplotly()

I managed to use @aosmith answer but the result is a little bit ugly enter image description here

firmo23
  • 7,490
  • 2
  • 38
  • 114
  • 1
    Maybe something along [these lines](https://stackoverflow.com/a/36337286/2461552)? – aosmith Jun 07 '18 at 21:23
  • useful but I cannot implement it appropriately – firmo23 Jun 07 '18 at 22:48
  • Is the ultimate goal here a static plot (using `ggplot2`), or an interactive one (using `plotly`)? Some ggplot elements aren't preserved appropriately when converting from one to the other, so solutions for the former may not always work. – Z.Lin Jun 08 '18 at 01:09
  • My goal is to create an interactive plot using ggplotly. I also updated the question – firmo23 Jun 08 '18 at 11:22
  • 1
    I implemented aosmith answer but the result is little bit strange as you can see in my edit. – firmo23 Jun 08 '18 at 12:44

0 Answers0