With this sort of combined plot, it is often easier to make them all separately before trying to join them together:
library(ggplot2)
# line plot
p.line <- ggplot(myd,aes(x=pos)) +
geom_line(aes(y=linevar)) + # plot the line using linevar
# draw the scales. NOTE: position[1] should be 0 not 1.
scale_x_continuous(breaks=position,labels=label)
# bar plot
p.bar <- ggplot(myd,aes(x=pos)) +
geom_bar(aes(y=barvar),stat='identity') + # plot the bar chart
scale_y_reverse() # reverse y scale
# heat plot
p.heat <- ggplot(myd,aes(x=pos)) +
geom_tile(aes(y=-.5,fill=heatmapvar,height=.5)) + # draw heatmap
scale_fill_gradient(low="yellow",high="red") # colour scale
You can use print(p.xxx)
to see what they look like.
Now we can combine them all together using grid.arrange
in gridExtra
:
library(gridExtra)
grid.arrange(p.line,p.heat,p.bar)
It looks like this:

(Note - my bar chart gave a warning because I have a negative barvar
- I assume the data you actually are going to use won't have this problem).
Now, the heat map looks a bit ugly and it looks like you want it drawn onto the line map, so we can add it on to the line map instead:
I don't want the heat map to be drawn over the line so I'll set its pos and height myself:
hght <- .25 # just looked nice - you'll have to adjust based on your data
ypos <- min(myd$linevar)-hght
p.line2 <- p.line +
geom_tile(aes(x=pos-.5,y=ypos, fill=heatmapvar, height=hght)) +
scale_fill_gradient(low="yellow",high="red") +
opts(legend.position="none") # <-- turn off the heatmap legend.
# print(p.line2)
Note - I added in a x=pos-.5
because otherwise geom_tile
centres the tiles about the x value which doesn't line up (try without the x=pos-.5
to see what I mean).
labeling positions
label <- c("A", "B", "C", "D", "E", "F", "G", "H", "I")
position <- c(1, 5, 10, 15, 20, 25, 30, 35, 40)
Now when I arrange these:
grid.arrange(p.line2,p.bar)
It looks like:

As to tweaking colours, adding in titles, etc - you can do that.
I'd recommending tweaking the individual graphs to get them how you like, and then only combine them at the end.
The ggplot2 documentation is helpful (although I find that general googling for 'ggplot2 heatmap' (e.g.) is more helpful in terms of getting examples to work off).