I would like to make a heatmap that displays both magnitude and p-value of the number in each box. I want the color of each cell to describe the value (v) and I want the thickness of the border of each cell to describe the p-value.
df = data.frame(x=1:5, y=letters[1:5], v=1:5, p=10^(-(1:5)) )
What I have:
plt <- ggplot(df, aes(x=x,y=y,fill=v)) + geom_tile()
I've got a first pass, this code changes the border thickness in correspondence with the significance of the value:
plt <- ggplot(df, aes(x=x, y=y, fill=v)) +
geom_tile( size=1-df$p, colour='black' )
Now I'm just trying to clean up the figure. How can I add regular spacing between all cells? I need to create a buffer zone so the borders don't have overlap with neighboring cells?
answer: height and width variables in aes
Here is the figure I end up with:
plt3 <- ggplot(mel, aes(y=Subject,x=HMO,fill=b,height=.75,width=.75 ))+
geom_tile(size=3*(mel$border)) +
scale_fill_gradientn(colours=rev(c("blue1",'lightblue', "white" ,'orangered', "red1")) )
I need a legend for the borders but I cant get it to appear. I think it is because it is not an aes. Any idea of how I can get a legend for the border thickness?