0

I'm trying to generate heat map with geom_tile, where the fill of the plot is determined by one parameter and transparency of plot determined by second parameter. I managed to obtain the plot I wanted but failed to make adjustment on the legend for alpha.

The continuous data for alpha ranged from 38 to 64, but the legend was showing from 40 to 60, which might be misleading.

I would like to adjust the legend so as it started from 0 up to 100. Also, curious why didn't the legend for alpha work like color, which come with gradient by default.

Any suggestions will be greatly appreciated.

> ggplot(mapxspGC_sort, aes(x=Genes, y=SpName, fill=Presence, alpha=GC))+
+ geom_tile() + labs(x="Genes", y="Species",color="%GC")+
+ scale_fill_gradient(low="white",high="black",guide=FALSE)
+ theme_bw()+theme(panel.grid.major=element_line(linetype="blank"))

Here's part of the long heatmap plot:

enter image description here

I have tried to add scale_alpha_continuous(range=c(0,100)) and scale_alpha_continuous(limit=c(0,100)), but they didn't work.

web
  • 105
  • 9

1 Answers1

0

What you're looking for are the limits and breaks parameters of scale_alpha_continuous:

scale_alpha_continuous(limits = c(0,100), breaks = c(0,25,50,100))
Snipeskies
  • 258
  • 1
  • 5
  • Hi, thanks for the help! Btw, do you have any idea how can I make the legend continuous? Is it actually possible for `alpha`? – web May 01 '21 at 01:41
  • 1
    Unfortunately, to my knowledge it isn't possible to make a legend for alpha continuous with ggplot. A hacky work around is to use ```color``` instead of ```alpha``` and use transparent colors (https://stackoverflow.com/questions/23201134/transparent-argb-hex-value) – Snipeskies May 01 '21 at 03:37