I would like to put a legend horizontally in the plot area. I am failing. If I set legend.position to a set of coordinates, it won't produce a horizontal legend. If, I set legend position to "bottom", it will produce a horizontal legend, but now (of course) it is outside of the plot area). Any help with this mystery would be appreciated. (note, the real data has negative values so scale_colour_gradient2 will display the red)
p <- ggplot(diamonds, aes(x, y))+
geom_point(aes(colour=carat))+
scale_colour_gradient2(low="red",mid="white",high="blue", name="this is\nthe legend")+
theme(legend.text = element_text(size=12),
legend.key.size = unit(1.5, "lines"),
legend.key = element_blank(),
legend.position = c(0.1,0.17),
#legend.position = "bottom",
legend.box = "horizontal" )
x11()
p