Ordering x-axis on correlation heat map using ggplot

前端 未结 3 1774
盖世英雄少女心
盖世英雄少女心 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:27

    This works for me:

    keep$Var1 <- factor(keep$Var1, levels = unique(keep$Var1), ordered = TRUE)
    keep$Var2 <- factor(keep$Var2, levels = unique(keep$Var2), ordered = TRUE)
    
    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())
    

    enter image description here

提交回复
热议问题