Home > database >  Change order of data plotted in ggtile
Change order of data plotted in ggtile

Time:08-04

I'm trying to plot my data in the order specified in the table, but I can't work out how. I think I've managed to change the levels(?) but not the factors(?)

Link to my data: gene heatmap current result

I hope I've included everything I needed to!

CodePudding user response:

The levels of your Species column have not been modified in your code, so you will need this line to make it registered :

BfrLong$Species=factor(BfrLong$Species,levels=Bfr$Species)

Pay attention to the name of your objects in your example, there is BfrLong and BigTreeLong but this should work :

BigTree <- read_csv(file = "/cloud/project/Phylogeny/RtreeData.csv")

Bfr <- BigTree[with(BigTree, order(-BfrA, -BfrB, -Bfd, -Ftn, -DPS, 
                                   -Rubrerythrin, -EncFtn, -NEEF)), ]
BfrLong <- pivot_longer(Bfr, 2:9) 
colnames(BfrLong) <- c("Species", "Protein", "Presence")

BfrLong$Species=factor(BfrLong$Species,levels=Bfr$Species)

ggplot(BfrLong, aes(Protein, Species, fill= Presence))   
  geom_tile(color = "white", linetype = 1)  
  scale_fill_gradient(low = "darkgreen", high = "olivedrab3")  
  labs(title = "Ferritins present in different bacteria", 
       x = "Ferritin family proteins", 
       y = "Species", 
       fill = "Presence of protein")  
  theme_minimal()  
  theme(axis.text.x = element_text(angle=45, hjust=1, size=8))  
  theme(axis.text.y = element_text(angle=0, hjust=1, size=6))  
  scale_x_discrete(limits = c("BfrA", "BfrB", "Bfd", "Ftn", "DPS", 
                              "EncFtn", "NEEF", "Rubrerythrin"))

enter image description here

  • Related