2

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' )

enter image description here

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")) )

enter image description here

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?

user3030872
  • 367
  • 1
  • 6
  • 14
  • 1
    Are you interested in thickness of border or tile thickness? You can control tile thickness with `width` argument in the tile geom. `plt <- ggplot(df, aes(x=x,y=y,fill=v)) + geom_tile(width = df$p*10)` – sriramn May 27 '15 at 22:36
  • Thanks, I'm working on border width not cell width. I included the code above. Can you like the question so that I can post my figure? I'm pretty new to ggploting so I could use some help cleaning up the figure. – user3030872 May 27 '15 at 22:45
  • Sorry, i was paraphrasing. I fixed it. – user3030872 May 27 '15 at 23:44
  • 3
    To reduce the tile size, add`h=0.95, w=0.95` (or whatever values work) inside `geom_tile`. The default is 1 for both `h` and `w`. – eipi10 May 27 '15 at 23:58
  • @eipi10 how can I get a legend to show up corresponding to the border thickness (detailed in the edited question above) – user3030872 May 29 '15 at 05:42
  • Can't test right now, but I think if you change to aes(size=3*border) then you'll get a legend. – eipi10 May 29 '15 at 14:34

0 Answers0