I imported my data into R and melted it to make a geom_tile
heat map. My input file looks like this:
sample,variable,value
chickenpox,person1,7
measles,person1,5
mumps,person1,2
diptheria,person1,8
chickenpox,person2,3
measles,person2,4
mumps,person2,0
diptheria,person2,8
chickenpox,person3,1
measles,person3,2
mumps,person3,7
diptheria,person3,2
chickenpox,person4,1
measles,person4,2
mumps,person4,5
diptheria,person4,1
Then I run:
b<-read.csv(file.choose(),header=TRUE)
q <- ggplot(data=b, aes(x=variable, y=sample, fill=value))
q + geom_tile()
And I am given this picture:
The problem is: The y axis automatically alphabetizes it. My data shouldn't be in alphabetical order, but in a specific order. How can I have the heat map display sample
as the y-axis
and variable
as the x-axis
, while maintaining the imported order of sample
?
It would be a major hassle for me to retype the sample column for each of the 460 factors that sample has for each person.
There has to be a faster way.