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:
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