1

I have the following code, that generates the following heatmap in R.

ggplot(data = hminput, color=category, aes(x = Poblaciones, y = Variantes)) +
  geom_tile(aes(fill = Frecuencias)) + scale_colour_gradient(name = "Frecuencias",low = "blue", high = "white",guide="colourbar")

enter image description here

hminput is a data frame with three columns: Poblaciones, Variantes and Frecuencias, where the first two are the x and y axis and the third one is the color reference.

And my desired output is that the heatmap to have a bar as the reference instead of those blocks, and also that the coloring is white-blue gradient instead of that multicolor gradient. To achieve that, I tried what's in my code, but I'm not achieving what I want (I'm getting the graph you see in the picture). Any thoughts? Thanks!

As some people asked, here is the dput of the data frame :

> dput(hminput)
structure(list(Variantes = structure(c(1L, 2L, 3L, 4L,...), .Label = 
c("rs10498633", "rs10792832", "rs10838725", 
"rs10948363", ..., "SNP"), class = "factor"), 
Poblaciones = c("AFR", "AFR", ...), Frecuencias = structure(c(12L, 
10L,...), .Label = c("0.01135", "0.0121", 
"0.01286", "0.01513", "0.02194", "0.05144", "0.05825", "0.059", 
"0.07716", "0.0938", "0.1051", "0.1225", "0.1346", "0.1407", 
"0.1566", "0.1604", "0.1619", "0.1838", "0.1914", "0.1929", 
..., 
"0.45", "0.5", "0.4"), class = "factor")), .Names = c("Variantes", 
"Poblaciones", "Frecuencias"), row.names = c("frqAFR.33", "frqAFR.31", 
"frqAFR.27", "frqAFR.14", "frqAFR.24",...
), class = "data.frame")
msimmer92
  • 397
  • 3
  • 16
  • 1
    use `scale_fill_gradient()` instead? – Nate Jun 11 '17 at 20:56
  • It says "Error: Discrete value supplied to continuous scale" – msimmer92 Jun 11 '17 at 21:27
  • 2
    Is `Frecuencias` a numeric variable? You may need to convert this column to numeric. – www Jun 11 '17 at 21:41
  • 1
    If you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) you are more likely to get help. – M-- Jun 11 '17 at 23:11
  • 1
    Jackpot , @ycw ! I added as.numeric(Frecuencias) instead of Frecuencias and it worked ! Thank you :) if you comment it as an answer i can select it as the main one. – msimmer92 Jun 12 '17 at 00:34
  • Please use `dput(hminput)` to show us your sample data – lebelinoz Jun 12 '17 at 01:25
  • There you go. I edited and added it at the bottom, but a shorter version because it was huge – msimmer92 Jun 12 '17 at 19:24
  • @melunuge92 seriously? because it's huge you put `...` in the middle of `structure`? If you read the link that I provided it tells you how to make a minimal example of your data-set. – M-- Jun 20 '17 at 15:32

0 Answers0