I am trying to create a heatmap using ggplot and geom_tile. The fill colour is based on my x values and alpha based on values. Based on small example (left), I would like my Plot to look similar to this example (right). Two problems:
- I get errors for the character elements on my alpha scale - is it possible to treat them like NA/ ignore them?
- Actual NA values are coloured in the same colour as the group they belong to, rather than all getting a grey fill.
The real Data is much larger and contains facets.. hope this doesn't mess up any possible solution. Here is my example Dataset and my (semi-working) code:
X <- rep(st, each=3)
Y <- rep(st, times=3)
Values<- c('Apple', 2,3,NA, "Banana", 3,1,2,"Pear")
Data <- data.frame(X,Y,Values)
ggplot(Data, mapping = aes(x=X, y=Y, fill=X,
alpha=Values # excluding this part I get a result, just not as I want it
)) +
geom_tile(colour="white") +
ylab("Y") +
xlab("X")+
scale_fill_manual("Assay",
values = c( 'red', 'yellow', 'green'),
na.value = 'grey')+
scale_alpha("Value", na.value = 0.02)+
ggtitle("Results Summary")+
theme( strip.text.y.left = element_text(angle = 0))+
geom_text(label=Data$Values)
Thanks in advance for any help :)