Ordering x-axis on correlation heat map using ggplot

前端 未结 3 1799
盖世英雄少女心
盖世英雄少女心 2021-01-26 04:49

I am trying to create a correlation heat map using ggplot, but I cannot seem to control the order of my variables on the x or y axis. Specifally, ggplot seems to try to order t

3条回答
  •  既然无缘
    2021-01-26 05:24

    Try this if the padded zero solution doesn't fit for your purpose:

    cust_breaks<-unique(keep$Var1[order(as.numeric(gsub("x","",keep$Var1)))])
    
    ggplot(keep,aes(Var1,Var2),xlab=NULL,ylab=NULL) + 
      geom_tile(aes(fill = value),colour = "white") + 
      scale_fill_gradient(low = "white",high = "steelblue") + 
      theme(axis.title.x=element_blank(),axis.title.y=element_blank()) +
      scale_x_discrete(limits=cust_breaks) + 
      scale_y_discrete(limits=cust_breaks)
    

提交回复
热议问题