在将某些图与子图结合后,y轴标签文本被隐藏

时间:2018-06-19 12:50:36

标签: r ggplot2 plotly subplot

我有以下数据集:

gene_symbol<-c("DADA","SDAASD","SADDSD","SDADD","ASDAD","XCVXCVX","EQWESDA","DASDADS","SDASDASD","DADADASD","sdaadfd","DFSD","SADADDAD","SADDADADA","DADSADSASDWQ","SDADASDAD","ASD","DSADD")
panel<-c("growth","growth","growth","growth","big","big","big","small","small","small","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDA<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDb<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDAf<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDAf1<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDAf2<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDAf3<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDAf4<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDAf5<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDA1<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDb1<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDAf1<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDAf11<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDAf21<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDAf31<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDAf41<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
ASDDAf51<-c("normal","over","low","over","normal","over","low","over","normal","over","DF","DF","DF","DF","DF","DF","DF","DF")
Gene_states22<-data.frame(gene_symbol,panel,ASDDA,ASDDb,ASDDAf,ASDDAf1,ASDDAf2,ASDDAf3,ASDDAf4,ASDDAf5,ASDDA1,ASDDb1,ASDDAf1,ASDDAf11,ASDDAf21,ASDDAf31,ASDDAf41,ASDDAf51)

然后,根据diffrenet panel类型的数量创建4个热图。如您所见,我只希望第一个显示y轴文本,这就是为什么我与其他文本分开创建的原因。

library(plotly)
library(ggplot2); library(reshape2)
HG3<-split(Gene_states22[,1:15], Gene_states22$panel)
HG4 <- melt(HG3, id.vars= c("gene_symbol","panel"))
HG4<-HG4[,-5]
HG5<-split(HG4, HG4$panel)
p<-list()

p[[1]]<-ggplotly(
  ggplot(HG5[[1]], aes(gene_symbol,variable)) + geom_tile(aes(fill = value),
                                                          colour = "grey50") + scale_fill_manual(values=c("white", "red", "blue","black","yellow","green","brown"))+
    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.x = element_text(family = "sans serif", 
                                     size = 11),
          axis.text.y= element_text(family = "sans serif", 
                                    size = 11),
          axis.title.y = element_text(vjust = 10,hjust = 10),
          panel.background = element_rect(fill = NA),
          panel.grid.major = element_line(colour = "grey50"),
          panel.spacing = unit(0, "lines"),
          strip.placement = "outside")
)%>%
  layout( autosize = F,hoverlabel = list(bgcolor = "white",
                                                                     font = list(family = "sans serif", 
                                                                                 size = 9, 
                                                                                 color = "black"))) 

然后我创建其余的

for(i in 2:length(HG5)){


  p[[i]]<-ggplotly(
    ggplot(HG5[[i]], aes(gene_symbol,variable)) + geom_tile(aes(fill = value),
                                                            colour = "grey50") + scale_fill_manual(values=c("white", "red", "blue","black","yellow","green","brown"))+
      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.x = element_text(family = "sans serif", 
                                     size = 11),
            axis.title.y = element_blank(),
            axis.text.y=element_blank(),
            panel.background = element_rect(fill = NA),
            panel.grid.major = element_line(colour = "grey50"),
            panel.spacing = unit(0, "lines"),
            strip.placement = "outside")
  )%>%
    layout( autosize = F,hoverlabel = list(bgcolor = "white",
                                                                       font = list(family = "sans serif", 
                                                                                   size = 9, 
                                                                                   color = "black")))
  }

最后我将它们与subplot

结合在一起
subplot(p)

问题在于,您无法在图片中看到y轴测试。 enter image description here

1 个答案:

答案 0 :(得分:2)

当您致电subplot时将其删除。您可以使用以下方式找回它:

subplot(p) %>% layout(yaxis = list(title = "sample"))

enter image description here