Reputation: 1
I have converted a large dataset into a two-way frequency table and want to present it in a heatmap graph, with the colours representing the frequency. I've managed to make a heatmap, but it only marks the frequency in a block colour, so you can't tell the difference if the frequency is 1 or 100, only that it is not 0.
I tried making the heatmap with the actual frequency table from the original data, but it did not work. I've been using the main data table instead to produce the heatmap.
This is as far as I have gotten to make the heat block without the colour indicating frequency. I made the frequency table:
PBP3.1Tab_alleleXemmtype <- table(PBP3.1_Table_Master$main_emm, PBP3.1_Table_Master$allele)
But this didn't work when I tried to make the heatmap. This is what I did to make a heatmap without colour = frequency:
ggplot(PBP3.1_Table_Master, aes(main_emm, allele)) +
geom_tile(aes())
From here, I would like to have the colours represent frequency, but I've tried using this and it makes no difference to the colour:
ggplot(PBP3.1_Table_Master, aes(main_emm, allele)) +
geom_tile(aes()) +
scale_fill_gradient(low = "white", high = "blue")
I've attached a photo of what the graph looks like. enter image description here
Upvotes: 0
Views: 75
Reputation: 56219
Aggregate then plot:
d <- as.data.frame(table(mtcars[, c("cyl", "gear")]))
ggplot(d, aes(cyl, gear, fill = Freq)) +
geom_tile() +
scale_fill_gradient(low = "white", high = "blue") +
coord_equal()
Upvotes: 1